0% found this document useful (0 votes)
7 views

Unit III

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Unit III

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 89

What is an Operating System?

■ A program that acts as an intermediary


between a user of a computer and the
computer hardware.
■ Operating system goals:
■ Execute user programs and make solving user
problems easier.
■ Make the computer system convenient to use.
■ Use the computer hardware in an efficient
manner.
Operating System Definition
(Cont.)
■ OS is a resource allocator
■ Manages all resources
■ Decides between conflicting requests for
efficient and fair resource use
■ OS is a control program
■ Controls execution of programs to prevent
errors and improper use of the computer
Operating System Definition
(Cont.)
■ No universally accepted definition
■ “The one program running at all times on the
computer” is the kernel. Everything else is
either a system program (ships with the
operating system) or an application program
Computer System Structure
■ Computer system can be divided into four
components
■ Hardware – provides basic computing resources
■ CPU, memory, I/O devices
■ Operating system
■ Controls and coordinates use of hardware among various
applications and users
■ Application programs – define the ways in which the system
resources are used to solve the computing problems of the
users
■ Word processors, compilers, web browsers, database systems,
video games
■ Users
Four Components of a
Computer System
System Components (cont.)
■ The OS provides for proper use of
resources in the operation of the
computer system.
■ OS is similar to government, no useful
function by itself.
■ It provides an environment within which
other programs can do useful work.
User view (cont.)
■ The user view of computer varies A/C to interface
being used most computer user.
■ The goal is maximize work that user is
performing is easier.
■ The user share resource and may exchange
information.
■ The OS in such case is designed to maximize
resource utilization to assure all available CPU
time, memory and I/O are used efficiently.
System View
■ Computer point of view, OS is the program
most intimately involved with hardware.
■ A computer solve problem CPU time,
memory space, file storage ,I/O devices
■ The OS acts as manager of these resources.
■ The OS must decide how to allocates the
specific program And users can operates
computer system efficiently.
Operating System Services

■ OS provides type of services for reading


& writing records these services are
categorized into three major heads
■ Information Management (IM)
■ Process Management (PM)
■ Memory Management (MM)
Information Management
■ Information management refers to a set of
services used for storing retrieving modify or
removing the information of various devices.
■ The Organization of information in terms of
directories and files allocating and
deallocating the sectors to various files,
maintaining and enforcing the access control
Some of the system calls

■ Create a file
■ Create a directory
■ Open a file (for read ,write,or both)
■ Close a file
■ Read data from file to buffer
■ Write a data from buffer to file
■ Move the file pointer
■ read & return file status
■ Create a link
■ Change working directory
Process Management

■ The services provides through process


management if the OS supports multiple user.
■ In modern multi user Os a number of user are
located at different terminals run the same or
different programs
■ A computer has only one CPU,
■ The CPU has only one set IR,PC,MAR,& MBR &
other Register
Process Management
(cont.)
■ At a given time it can execute only one
instruction belonging to any one of
these programs computing for CPU.
■ The function of OS is to keep track of the
computing process, schedule them,
dispatch them one after other
Some System Calls

■ Create a child process identical to the parent


■ Wait for child process to terminate
■ Terminate a process
■ Changing the priority of a process
■ Block a process
■ Dispatch a process
■ Suspend a process
■ Return a process
■ Delay a process
■ fork a process
■ Ready a process
Memory management
■ The services provided under memory
management (MM) are directed to keeping track
of memory and allocating / deallocating it to
various processes
■ The OS keeps a list of free memory locations.
■ Before a program is loaded in the memory from
the disk.
■ The MM consult free list allocates the memory to
the process depending upon the program size &
updates the list of free memory.
Some system calls
■ Allocated a chunk of memory to the
process
■ Free (release) a chunk of memory from a
process
Basic function of an Operating
System
■ Job accounting & log maintenance
■ OS with the help of an internal time
computes the time required by each
resources for different user
■ It also maintains a log & Keep track of login
& logout time of a particular users.
Memory management
■ The Os partitions the memory for
different users and programs. In
multi-user system memory allocation is
dynamic
■ The available memory for processing
differ t activates is managed by OS
Fault tolerance Management

■ Fault tolerance management is built in


with OS providing replication.
■ In the event of any interface or peripheral
device failure, the system automatically
switches over to the substitutes.
Command interpretation &
execution

■ OS reads the command entered by the


user checks for errors interpreter &
translate them to machine instruction &
executed by the hardware.
Communication
■ It is facility provided to users to
communicate with each other in the
same or other system by sharing or
transferring data.
Process Management &
scheduling
■ OS manages various peripheral &
resources of the computer instruction &
command and schedules the job for
CPU
Device Management
File & Data Management
Evolution of OS Function.
■ Os function have evolved in reference to the
following consideration.
■ Efficient utilization computing resources
■ New features in computer architecture
■ New User Requirement
■ Different OS address these issues in different
manner
■ All OS contains components for function of
memory & process management & protection
of user from one another.
JOB, Programs & Process
(cont.)
■ The primary function of an OS is to
organize the execution of user
computation in a computer system
■ a three characterization of user
computation have been used
■ JOB
■ PROGRAM
■ PROCESSES
PROGRAM

■ Program is the classical view of a


computation. It consist of a set of
programs units including programs
units obtained from libraries which
constitute an object code is executed
Process
■ A process is an execution of a program
or part of a program. It differ from
program when concurrent programming
techniques are used for coding the
programs
JOB
■ A job is computation structure which is
sequence of programs. It Consist of
sequence of job steps each job steps.
Type of operating System
■ Within the broad family of operating systems,
there are general types, categorized based on
the types of computers they control and the
sort of applications they support.
■ The categories are:
■ Batch Processing System
■ Multi-programming Systems
■ Time sharing systems
■ Multitasking systems
■ Real Time Operating Systems
Batch Processing
Multiprogramming System
■ Multiprogramming is one of the more basic types
of parallel processing that can be employed in
many different environments.
■ Essentially, multiprogramming makes it possible
for several programs to be active at the same
time, while still running through a single
processor.
■ The functionality of multiprogramming in this
environment involves a continual process of
sequentially accomplishing tasks associated
with the function of one program, then moving on
to run a task associated with the next program.
■ Multiprogramming is very different from the
multiprocessing because even though there may
be several programs currently active, the uni
processor is not simultaneously executing
commands for all the programs.
■ Instead, the processor addresses each program,
executes a single command, then moves on to the
next program in the queue.
■ The previous program remains active, but enters
into a passive state until the uniprocessor returns
to the front of the queue and executes a second
command.
■ The mechanism within multiprogramming
is known as an interrupt.
■ Each task is granted a specific amount of
time for processing before the operating
systems will move on to the next program
and the next task.
■ In a sense, multiprogramming is about
juggling several tasks at one time, quickly
performing one piece of the required
action, then moving to do something with
a different task before returning to the
former job.
■ Memory is important to the proper function
of multiprogramming.
■ Capacity should be ample enough to
ensure that if one program within the
rotating queue encounters a problem,
■ it does not prevent delays or impact the
operation of other open applications.
■ At the same time, some type of memory
protection should be in place.
Mac OS X Panther screen shot
Time sharing system
■ A time sharing system has many user terminals
simultaneously connected to the same computer.
■ Using these terminals, multiple user can
simultaneously work on the system.
■ The multiprogramming feature allows multiple user
programs to simultaneously reside in the main
memory.
■ The special CPU scheduling algorithm used in a time
sharing system, allocates a short period of CPU time
one by one to each user process
Requirement of time sharing
systems

■ Time sharing system typically require the following


additional hardware and software features
■ A number of terminal are simultaneously connected to
the system, so that multiple user can simultaneously
use the system in interactive mode
■ A relatively large memory to support
multiprogramming
■ Memory protection mechanism to prevent one job’s
instruction data from other jobs in a
multiprogramming environment
■ Job status preservation mechanism to preserve a job
complete sta
Multitasking
■ Multitasking is same as
multiprogramming Multitasking is
system capability to concurrent work
on more than one task (job or Process)
■ Whenever a task needs to perform I/O
operations, the CPU can be used for
executing some other task (job or
process).
■ The term multiprogramming for multi
user system ( System uses
simultaneously used by many user such
as main frame and server class system)
■ Multitasking for single user System (
system that are used by only one user at
a time such as personal computer or
note book computer )
Real Time Operating Systems
■ A Real-Time Operating System (RTOS)
is a multitasking operating system
intended for real-time applications
■ Such applications include embedded
systems, industrial robots, spacecraft,
industrial control and scientific research
equipment
System Calls
■ Defn :- A system call is a method by which a program
makes a request to the OS.
■ Software may trigger an interrupt by executing
special operation called system call or monitor call.
■ System call provides an interface to the services
made available by an OS .
■ These system calls are generally available as
routines written C and C++ ,although certain low
level tasks ,may be written in assembly language
instruction.
■ System calls are implemented using the
interrupt hardware of a computer system.
Type of System Calls

■ System call can be grouped roughly into


five major categories
■ Process control
■ File Management
■ Device Management
■ Information Management
■ Communication
Operating System Design and
Implementation
■ Internal structure of different Operating Systems
can vary widely
■ Start by defining goals and specifications
■ Affected by choice of hardware, type of system
■ goals and goals
■ User goals – operating system should be convenient to
use, easy to learn, reliable, safe, and fast
■ System goals – operating system should be easy to
design, implement, and maintain, as well as flexible,
reliable, error-free, and efficient
Operating System Design and
Implementation (Cont.)

■ Important principle to separate


Policy: What will be done?
Mechanism: How to do it?
■ Mechanisms determine how to do something,
policies decide what will be done
■ The separation of policy from mechanism is a
very important principle, it allows maximum
flexibility if policy decisions are to be changed
later
Simple Structure
■ MS-DOS – written to provide the most
functionality in the least space
■ Not divided into modules
■ Although MS-DOS has some structure, its
interfaces and levels of functionality are not
well separated
MS-DOS Layer Structure
Layered Approach
■ The operating system is divided into a
number of layers (levels), each built on
top of lower layers. The bottom layer
(layer 0), is the hardware; the highest
(layer N) is the user interface.
■ With modularity, layers are selected such
that each uses functions (operations)
and services of only lower-level layers
Layered Operating System
WHAT IS PROCESS

■ Difference between program and process,in simple term “A


program does not compete for the computing resources like
the CPU or the memory where as process does”.
■ A program may exit on paper or reside on the disk.
■ It may be compiles or tested but it still dose not compete for
CPU time and other resources.
■ Once user wants to execute a program, it is loaded in main
memory at which time it becomes a process, because it is an
which competes for CPU time
■ Other way “ program under execution, which competes for the
CPU time and other resources”
Process in Memory
■ A process is a program execution,
Stack process is more than program code
which some terms known as text
section.
■ It also include current activity, as
represented by value of program
counter and the contents of
heap processor register
■ A process generally also include
Data process stack which contains
temporary data such as functions
Text parameter ,return address and local
variable and data section which
contains global variables
Process in Memory (cont).
■ A process may also include heap, which
is memory that is dynamically allocated
during process run time.
CPU Switch From Process to Process
Process State
■ As a process executes, it changes
■ new: The process is being created
■ running: Instructions are being executed
■ waiting: The process is waiting for some event to
occur
■ ready: The process is waiting to be assigned to a
processor
■ terminated: The process has finished execution
Diagram of Process State
Process Control Block (PCB)
■ Each process is represented in the operating
system by a process control block also called
task control block
■ Information associated with each process
■ Process state
■ Program counter
■ CPU registers
■ CPU scheduling information
■ Memory-management information
■ Accounting information
■ I/O status information
Process Control Block (PCB)
The fields in PCB
■ Process ID :- Number is allocated by OS to the
process Creation. The OS normally sets a
limit on maximum number of process that it
can handle and schedule. Assume that
number is n , means that the PID can takes
on values between 0 to n-1
■ Process State :- new,ready,running ,waiting,
halted and so on
Process Priority
■ some Process are urgently required to
be completed than others.
■ This priority can be set externally by the
user /system manager or it can decided
by the operating system internally
depending upon various parameter.
Register Save Area.
■ This is needed to save all the CPU register
at the Context Switch.
Pointer to process Memory.
■ This gives the direct or indirect address or
pointer to the location where the process
image reside in the memory
■ For instance in paging system it could
point toward the page map table which is
turn to point toward the physical memory .
Pointer to other resource
■ This gives pointer to the other data
structure maintained for the process
List of open Files
■ This can be used by OS to closed all
open files not closed by the process
explicitly.
Accounting Information
■ This gives the account of resources such
as CPU time, Connect time ,Disk I/O
used etc by the process.
■ It had to collect all the information and
update the PCB’s with it for different
process.
Other Information
■ This contains path name of current
directory
■ At the time of logging in the home
directory mentioned in the system file.
■ Useful information is maintained by the
Operating System in the PCB.
Pointer to other PCBs
■ This gives the address of next PCB’s
(PCB number) within the specific
category.
■ the OS maintains a list of ready
processes
Scheduling
■ Scheduling is the activity of determining
which services request should be handle
next by a server
■ Scheduling is important because it
influence user services and efficiency of
cpu utilization
Scheduling policy
■ Four events related to scheduling

■ Arrival
■ Scheduling
■ Preemption
■ Completion
Arrival

■ A request arrive in the system when a


user submit it to OS. When a request
arrives, the system takes its arrival time,
■ The information is entered into a list of
pending request, some information
associated with a request.
Scheduling
■ A request is scheduled when the
scheduler select it for servicing
Scheduling Criteria
■ Different CPU scheduling algorithm have
different properties. Many criteria have
been suggested for CPU scheduling
algorithms.
■ CPU Utilization
■ Throughput
■ Turnaround time
■ Waiting time
■ Response time
CPU Utilization
■ We want to keep the CPU as busy
possible.
■ CPU utilization can be range from 0
to100 %
■ In real system it should be range from
40 % (lightly loaded system) to 90 %
Throughput
■ If the CPU is busy executing process,
then work is being done.
■ Measure of work is number of process
that are completed per unit time that is
called throughput .
■ For long process, this rate may be one
process per hour; for short time it may
be 10 process per second.
Waiting time
■ The CPU scheduling does not affect the
amount of time during which a process
execute or does I/O
■ It affect only the amount of time that the
process spends waiting in the ready
queue.
■ Waiting time is sum of the periods spent
waiting in the ready queue
Turnaround time
■ The interval from of submission of a
process to the time of completion is the
turnaround time
■ Turnaround time is the sum of period
spent waiting to get into memory,
waiting in the ready queue, executing on
the CPU, and doing I/O
Response time
FIRST COME FIRST SERVED
SCHEDULIGN (FCFS)
■ In this scheduling, the process that request the
CPU first is allocated the CPU first.
■ The implementation of the FCFS policy is
easily managed with a FIFO queue
■ When the process enter the ready queue, its
PCB is linked onto the tail of the queue. When
the CPU is free it is allocated to the process at
the head of the queue. The running process is
removed from queue.
For example
Process Burst Time
24
3
3

■ Suppose that the processes arrive in the order: , ,


The Gantt Chart for the schedule is:

P1 P2 P3

0 24 27 30

■ Waiting time for = 0; = 24; = 27


■ Average waiting time: (0 + 24 + 27)/3 = 17
FCFS Scheduling (Cont.)
Suppose that the processes arrive in the order
, ,
■ The Gantt chart for the schedule is:
P2 P3 P1

0 3 6 30

■ Waiting time for 6 =0 3


■ Average waiting time: (6 + 0 + 3)/3 = 3
■ Much better than previous case
■ short process behind long process
FCFS Scheduling (Cont.)
■ The FCFS algorithm is non preemptive
■ Once the cpu has been allocated to a
process, that process keeps the CPU
until it release the CPU either by
terminating or by requesting I/O.
SHORTEST JOB FIRST
SCEDULING (SJF)
■ SJF is associates with each process the
length of the process’s next CPU burst.
■ When the CPU is available, it is assigned
to the process that has the smallest next
CPU brust.
■ If the next CPU Burst of two process are
same, the FCFS scheduling is used to
break the tie.
SHORTEST JOB FIRST SCEDULING
(cont.)
■ Scheduling depends on the length of the next
CPU burst of a process, rather than its total
length.
■ For textbook used by people
)
■ Two schemes:
■ Non preemptive – once CPU given to the process it
cannot be preempted until completes its CPU burst
■ preemptive – if a new process arrives with CPU
burst length less than remaining time of current
executing process, preempt. This scheme is know
as the
Shortest-Remaining-Time-First (SRTF
Example of Non-Preemptive SJF

Process Arrival Time Burst Time


0.0 7
2.0 4
4.0 1
5.0 4
■ SJF (non-preemptive)
P1 P3 P2 P4

0 3 7 8 12 16

■ Average waiting time = (0 + 6 + 3 + 7)/4 = 4


Example of Preemptive SJF
Process Arrival Time Burst Time
0.0 7
2.0 4
4.0 1
5.0 4
■ SJF (preemptive)
P1 P2 P3 P2 P4 P1

0 2 4 5 7 11 16

■ Average waiting time = (9 + 1 + 0 +2)/4 = 3


For ex
■ Process Burst time
P1 6
P2 8
P3 7
P4 3
The following set of processes with length of CPU
burst given in milisecond.
P4 P1 P3 P2
0 03 09 16 24

■The waiting time is p1 is = 3


■P2 = 16
■P3=9
■P4=0
■Average waiting time is = (3+16+9+0)/4=7
milisecond
Priority Scheduling
■ A priority is associated with each process and,
the CPU is allocated to the process with the
highest priority.
■ Equal priority process schedule in FCFS order
■ The larger CPU burst, the lowest the priority.
■ Priority are generally indicate by fixed rage of
numbers, such as 0 to 7 or 0 to 4095
Priority Scheduling (cont.)
■ Consider the set of process, assumed arrived
at time 0, in the order P1,P2,P3,P4,P5 with the
length of CPU burst given in milliseconds

Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Round Robin
■ Each process gets a small unit of CPU time (
), usually 10-100 milliseconds. After this time
has elapsed, the process is preempted and added to
the end of the ready queue.
■ If there are processes in the ready queue and the
time quantum is , then each process gets 1/ of the
CPU time in chunks of at most time units at once.
No process waits more than ( -1) time units.
■ Performance
■ large FIFO
■ small must be large with respect to context switch,
otherwise overhead is too high
Example of RR with Time
Quantum = 20
ProcessBurst Time
53
17
68
24
■ The Gantt chart is:

P1 P2 P3 P4 P1 P3 P4 P1 P3 P3

0 20 37 57 77 97 117 121 134 154 162

■ Typically, higher average turnaround than SJF, but better

You might also like