Chapter Two
Chapter Two
MANAGEMENT
Process Concept
An operating system executes a variety of programs:
Batch system – jobs
Time-shared systems – user programs or tasks
Textbook uses the terms job and process almost
interchangeably
Process – a program in execution; process execution must
progress in sequential fashion
A process includes:
program counter
stack
data section
difference b/n process and program
The difference between a process and a program is
subtle
process is an activity of some kind,It has a program,
input, output, and a state.
A single processor may be shared among several
processes
In contrast, a program is something that may be
stored on disk, not doing anything.
A process will need certain resources— such as
CPU time, memory, files, and I/O devices to
accomplish its task.
These resources are allocated to the process either
when it is created or while it is executing.
Process Creation
Operating systems need some way to create
processes.
Four principal events cause processes to be
created:
System initialization.
Execution of a process-creation system call by a
running process.
A user request to create a new process.
Initiation of a batch job.
A process may create several new processes, via
a create-process system call
The creating process is called a parent process
the new processes are called the children of that
process
Each of these new processes may in turn create
other processes, forming a tree of processes.
operating systems identify processes according to a
unique process identifier.(or pid)
A tree of processes on a typical Solaris
system.
When a process creates a new process, two possibilities
exist in terms of execution:
(1).The parent continues to execute concurrently with its children.
(2).The parent waits until some or all of its children have terminated.
There are also two possibilities in terms of the address
space of the new process:
(1).The child process is a duplicate of the parent process (it has the
same program and data as the parent).
(2).The child process has a new program loaded into it.
Process Termination
After a process has been created, it starts running and
does whatever its job.
Later the new process will terminate, usually due to one
of the following conditions.
1. Normal exit (voluntary)
Most processes terminate because they have done their
work.
When a compiler has compiled the program given to it,
the compiler executes a system call to tell the os(operating
system) that it is finished. e.g
This call is exit in UNIX
call ExitProcess in windows
2.Error exit (voluntary).
Termination due to the process discovers a fatal error.
example :
to compile the program foo.c and no such file exists, the
compiler simply announces this fact and exits.
3.Fatal error (involuntary).
Termination due to an error caused by the process.
example :
include executing an illegal instruction.
Referencing non-existent memory.
dividing by zero.
4.Killed by another process (involuntary)
Terminate due to the process executes a system call
telling the operating system to kill some other process.
The killer must have the necessary authorization to do in
the kill.
In UNIX this call is kill . The corresponding Winx32
function is TerminateProcess .
Process State
0 24 27 30
FCFS Scheduling (Cont)
Suppose that the processes arrive in the order
P2 , P3 , P1
The Gantt chart for the schedule is:
Waiting time for P1 = 6; P2 = 0; P3 = 3
Average waiting time: (6 + 0 + 3)/3 = 3
Much better than previous case
Convoy effect short process behind long
process
P2 P3 P1
0 3 6 30
Shortest Job First (SJF) Scheduling
Associate with each process the length of its next CPU
burst.
Use these lengths to schedule the process with the
shortest time
SJF is optimal – gives minimum average waiting time for a
given set of processes
The difficulty is knowing the length of the next CPU request
If the next CPU bursts of two processes are the same,FCFS
scheduling is used to break the tie.
SJF Scheduling (Continue...)
As an example of SJF scheduling, consider the following set of
processes,with the length of the CPU burst given in milliseconds:
Process Burst Time
P1 6
P2 8
P3 7
P4 3
The waiting time is 3 milliseconds for process P1 , 16 milliseconds for process
P2 , 9 milliseconds for process P3 , and 0 milliseconds for process P4
Gantt chart:
Process P 1 is started at time 0, since it is the only process in the queue. Process
P 2 arrives at time 1.
The remaining time for process P 1 (7 milliseconds) is larger than the time
required by process P 2 (4 milliseconds), so process P 1 is preempted, and
process P 2 is scheduled.
The average waiting time for this example is [(10 − 1) + (1 − 1) + (17 − 2) + (5 −
3)]/4 = 26/4 = 6.5 milliseconds.
Nonpreemptive SJF scheduling would result in an average waiting time of 7.75
milliseconds.
Priority Scheduling
A priority number (integer) is associated with each process
The CPU is allocated to the process with the highest priority
(smallest integer highest priority)
Preemptive
nonpreemptive
SJF is a priority scheduling where priority is the predicted
next CPU burst time
Problem Starvation – low priority processes may never
execute
Solution Aging – as time progresses increase the priority
of the process(decrease the value of the interger).
Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
Using priority scheduling, we would schedule these processes according to
the following Gantt chart.
0 4 7 10 14 18 22 26 30
Typically, higher average turnaround than SJF, but
better response
Let’s calculate the average waiting time for this schedule.
P1 waits for 6 milliseconds (10 – 4),
P 2 waits for 4 milliseconds,
P3 waits for 7 milliseconds.
Thus, the average waiting time is 17/3 = 5.66 milliseconds.
Time Quantum and Context Switch Time
Multilevel Queue Scheduling