Unit-2 Process Management
Unit-2 Process Management
UNIT- 2
PROCESS MANAGEMENT
2.1 Process Concepts
The program execution is called as process. A process is a more than one program code.
The program is a “Passive entity” means a file containing a list of instructions stored on
disk.
Process is an active entity with a program counter specifying the next instruction to
execute and set of associated resources.
Only one process can be running in running state at any instant of time but many
processes can be in ready or waiting state.
Process State
Process Number
Program
Counter
Registers
Memory Limits
.............. so on
1. Process State: The process state may be new, ready, running, waiting and terminated
state.
2. Process Number: It indicates the process number or ID for identifying it.
“Device Queue” are also exists in the system. The list of process waiting for a particular
I/O device is called “Device Queue” and each device has its own device queue. Each
device has its own device queue illustrated in figure 2.3
Each queue has a queue header which contains two pointers “Head and Tailed”. The
head pointer points to first process control block (PCB) and tail pointer points to the last
process control block (PCB) in the queue.
In addition, each PCB has a pointer which points to the next PCB in the list queue are
stored as “linked list”.
Each rectangular box represents a “Queue”. Two types of queue are available.
1. Ready queue
2. Device queue
A new process initially put in the “ready queue” and it waits for CPU. Once it is
allocated to the CPU, the following event will occurs:
Process could issue on I/O request and then be placed in an I/O queue.
Process could create a new sub process and wait for its termination.
Process time slot is expired and waits in the ready queue.
Process may be removed forcibly from the CPU due to interrupt.
2.2.3 Scheduler
Scheduler is a part of operating system which selects process from different queues. The
selection of process is carried out by the appropriate scheduler. The following are some of
the scheduler.
Long –term scheduler or Job scheduler : selects which processes should be brought into
the ready queue
The long-term scheduler selects processes from this pool (queue) and loads them
into memory for execution.
If the degree of multiprogramming is stable, then the average rate of process creation
must be equal to the average departure rate of processes leaving the system.
The long-term scheduler may need to be invoked only when a process leaves the
system.
Processes can be described as either:
o I/O-bound process – spends more time doing I/O than computations, many
short CPU bursts.
o CPU-bound process – spends more time doing computations; few very
long CPU bursts.
Short-term scheduler or CPU Scheduler: selects which process should be executed next
and allocates CPU
The short-term scheduler decides which of the processes are ready in main memory
for allocating to the CPU for execution.
The short-term scheduler executes more frequently.
In short-term scheduler, process may execute in few milliseconds before waiting
for an I/O request.
It executes the process in very high speed.
Medium-term scheduler
The idea of medium-term scheduler is to remove processes from memory and these
to reduce the degree of multiprogramming.
The process can be reintroduced into memory and its execution can be continued
where it left off. This scheme is called “Swapping”. The figure 2.5 illustrates the
medium-term scheduling.
In general, a process will need certain resources (CPU time, memory, files I/O devices) to
accomplish task. When a process creates a sub process, that sub process may be able to
obtain its resources directly from the operating system, or it may be constrained to a subset
of the resources of parent process
There are two types of process execution when a parent process creates new process or
child process.
fork()
exec() exit()
Child
A parent process may terminates the execution of child process for the following
reason:
The child has exceeded its usage of some of the resources it has been allocated.
The task assigned to the child process execution may not require further.
The parent is exiting and the operating system does not allow a child to continue if
its parent terminates
The Operating system does not permit further execution of child process, if parent process
has been terminated already. The operating system initiates a process called “Cascading
Termination”.
Any process that does not share data with any other process is independent.
2. Cooperating process
Any process that shares data with other process is a cooperating process.
2. Computation speed up: - Task can be divided into subtasks and each sub task can
be executing parallel with the help of multiprogramming system.
Process A
Shared
Process B
Kernel
Process A
M
Process B M
Kernel
M
Fig 2.8 Message passing
The following methods are used for implementing the communication link.
In direct, each process wants to communicate must explicitly name the recipient or sender
of the communication. Here send() and receive() functions are defined as follows –
In indirect, the messages are sending to and receive from “Mailboxes”. Each mailbox has
a unique identification. Here send() and receive() method are defined as follows
A member of links exists between each pair of process. Each link must have one
mailbox.
2. Synchronous or asynchronous
Message passing may be either “Blocking or non-blocking”.
Blocking send The sending process is blocked until the message is received by
the receiving process.
Non-blocking send The sending process sends the message and resumes
operations.
1. Zero CapacityThe queue has maximum length is zero, so link cannot have any
message waiting in it. The sender must wait until the recipient receives the
message.
2. Bounded CapacityThe queue has finite length. If the queue is not full or a new
message can be placed and sender can continue execution without waiting.
The zero capacity case is sometimes referred to as a message system with no buffering;
the other cases are referred to as systems with automatic buffering
In multi-processor system, all processes are running at all times to increasing the
CPU Utilization.
When a process switches from the waiting state to the ready state.
2.5.3 Dispatcher
The dispatcher is the module that gives control of the CPU to the process selected by the
CPU scheduler. The function of dispatcher as follows
1. Switching context
3. Jumping to the proper location in the user program to restart that program.
The time it takes for the dispatcher to stop one process and start another is known as
“Dispatcher latency”.
1. CPU Utilization: - The primary objective of CPU is to keep as busy. The CPU
utilization can range from 0 to 100%.
3. Turnaround time: - The interval from the time of submission of a process to the
time of completion is the “Turnaround time”.
4. Waiting time: - Waiting time is the sum of the periods spent waiting in the ready
queue or the amount of time that process sends in ready queue.
5. Response time: - Response time is the time from the submission of a request until
the first response is produced.
Optimization Criteria:
Max CPU utilization
Max throughput
Example 1: Three Processes P1, P2, P3 that arrives at zero (0) time with the CPU burst
time given in milliseconds.
Process Burst time
P1 24
P2 03
P3 03
Solution:
Gantt chart
P1 P2 P3
0 24 27 30
The right side value of a process in the Ghantt chart indicates completion time.
Unit of Time: milliseconds
P1 0 24 24 24 0
P2 0 3 27 27 24
P3 0 3 30 30 27
Total Time 30 81 81 51
Example-2:For the same above example if the processes arrive in the order of P2, P3,
P1at time 0.
Ghantt Chart
P2 P3 P1
0 3 6 30
Unit of Time:milliseconds
P.No AT BT CT TAT WT
P1 0 24 30 30 6
P2 0 3 3 3 0
P3 0 3 6 6 3
Total Time 30 39 39 9
Average TAT = (Total TAT)/(No.of Process)
= 39/3
= 13 ms
Average WT = (Total WT)/(No.of Process)
= 9/3
= 3 ms
From both the examples it can be inferred that change in the order of process arrival yield
different average turnaround time and waiting time, this is knows as convoy effect.
Example 3: -The three Processes P1, P2, P3 that arrives at time zero (0) with the CPU
burst time given in milliseconds.
Process Burst time
P1 22
P2 04
P3 02
Solution:
Gantt chart
P1 P2 P3
0 22 26 28
Unit of Time: milliseconds
P.No AT BT CT TAT WT
P1 0 22 22 22 0
P2 0 4 26 26 22
P3 0 2 28 28 26
Total Time 28 76 76 48
= 76/3
= 25.33 ms
Average WT = (Total WT)/(No.of Process)
= 48/3
= 16 ms
Example-4: Calculate average turnaround time and waiting time for the following
processes.
P.No AT BT
P1 0 4
P2 1 3
P3 2 1
P4 3 2
P5 4 5
Solution:
Ghant Chart
P1 P2 P3 P4 P5
0 4 7 8 10 15
Properties of FCFS
The average waiting time is generally not minimal and may vary substantially
A mix of CPU bound processes and I/O- bound processes may give rise to the convoy
effect-poor utilization of CPU and I/O devices
FCFS is non preemptive: process can hog the CPU
If CPU burst of next two processes the same , FCFS is used to break ties.
SJF is provably optimal in that it gives the minimum average waiting time.
The real difficulty with SJF is knowing the length of the next CPU request. So this is
suitable for long-term scheduling.
A Non-Preemptive SJF algorithm will allow the currently executing process to finish it
CPU burst.
Solution:
Gantt chart
P4 P1 P3 P2
0 2 8 16 26
Unit of Time: milliseconds
P.No AT BT CT TAT WT
P1 0 6 8 8 2
P2 0 10 26 26 16
Computer Science and Engineering 30
Operating System:15CS43T 2020-21
P3 0 8 16 16 8
P4 0 2 2 2 0
Total Time 26 52 52 26
Example-2:
Process Arrival Time Burst time
P1 0 7
P2 1 5
P3 2 1
P4 3 2
P5 4 8
Solution:
Gantt chart
P1 P3 P4 P2 P5
0 7 8 10 15 23
Unit of Time: milliseconds
P.No AT BT CT TAT WT
P1 0 7 7 7 0
P2 1 5 15 14 9
P3 2 1 8 6 5
P4 3 2 10 7 5
P5 4 8 23 19 11
Total Time 23 63 53 30
= 53/5
= 10.6 ms
= 30/5
= 6 ms
Preemptive SJF(shortest-remaining-time-first)scheduling:
A Preemptive SJF algorithm will preempt the currently executing process. Preemptive SJF
scheduling is called shortest remaining time first scheduling (SRTF).
The next CPU burst of the newly arrived process may be shorter that what is left off the
currently executing process. A preemptive SJF algorithm will preempt the currently
executing process.
In preemptive SJF, the completion time would be the right side value of a last
occurrence of a process in the Ghantt Chart
Example-1:
Process Arrival time Burst time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Solution:
Gantt chart
P1 P2 P2 P2 P2 P4 P1 P3
0 1 2 3 4 5 10 17 26
Unit of Time: milliseconds
P.No AT BT CT TAT WT
P1 0 8 17 17 9
P2 1 4 5 4 0
P3 2 9 26 24 15
P4 3 5 10 7 2
Total Time 26 58 52 26
= 52/4
= 13 ms
= 26/4
= 6.5 ms
Example-2:
Process Arrival time Burst time
P0 2 3
P1 4 6
P2 6 4
P3 8 5
P4 0 2
Solution:
Gantt chart
P4 P0 P0 P1 P2 P2 P1 P3
0 2 4 5 6 8 10 15 20
Unit of Time: milliseconds
P.No AT BT CT TAT WT
P0 2 3 5 3 0
P1 4 6 15 11 5
P2 6 4 10 4 0
P3 8 5 20 12 7
P4 0 2 2 2 0
Total Time 20 52 32 12
Average TAT = (Total TAT)/(No.of Process)
= 32/5
= 6.4 ms
= 12/5
= 2.4 ms
Advantages of SJF
Suitable for long-term (job) scheduler.
Can implemented in both pre-emptive and non pre-emptive.
Disadvantages of SJF
Difficult to known the length of next CPU burst time. Hence not suitable for
Short-term(CPU) scheduling
Priorities are generally indicated by some fixed range of numbers, such as 0 to 7 . ‘0’ as
the highest priority and 7 as the lowest priority
One solution against starvation is called aging: Aging is a technique where the priority
is gradually increased on processes that wait in the system for a long time
Non pre-emptive Priority Scheduling: In which a process is allowed to run till its
completion.
Example 1:- Consider the following processes with burst time and priority. Arrival time is
0 ms
Solution:
Gantt chart
P2 P5 P1 P3 P4
0 1 6 16 18 19
Unit of Time: milliseconds
P.No AT Priority BT CT TAT WT
P1 0 3 10 16 16 6
P2 0 1 1 1 1 0
P3 0 4 2 18 18 16
P4 0 5 1 19 19 18
P5 0 2 5 6 6 1
Total Time 19 60 60 41
= 60/5
= 12 ms
Average WT = (Total WT)/(No.of Process)
= 41/5
= 8.2 ms
Example-2: Consider the following processes with burst time and priority. Arrival time is
0 ms
Process Burst time Priority
P1 5 3
P2 4 2
P3 2 1
P4 3 5
P5 8 4
Solution:
Gantt chart
P3 P2 P1 P5 P4
0 2 6 11 19 22
Example-1:
Process Arrival Time Burst Priority
P1 0 time
5 3
P2 1 4 2
P3 2 2 1
P4 3 3 5
P5 4 8 4
Solution:
Gantt chart
P1 P2 P3 P3 P2 P1 P5 P4
0 1 2 3 4 7 11 19 21
Unit of Time: milliseconds
P.No AT Priority BT CT TAT WT
P1 0 3 5 11 11 6
P2 1 2 4 7 6 2
P3 2 1 2 4 2 0
P4 3 5 3 21 18 15
P5 4 4 8 19 15 7
Total Time 22 62 52 30
Average TAT = (Total TAT)/(No.of Process)
= 52/5
= 10.4 ms
Average WT = (Total WT)/(No.of Process)
= 30/5
= 6 ms
2.7.4 Round Robin (RR) scheduling
RR Scheduling is designed especially for time-sharing systems.
If the time quantum is large, The RR policy is same as that of FCFS policy.
Solution:
Circular Queue
P1 P2 P3 P1 P1 P1 P1 P1
Gantt chart
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
= 47/3
= 15.66 ms
Average WT = (Total WT)/(No.of Process)
= 17/3
= 5.66 ms
Solution:
Circular Queue
P1 P2 P3 P1 P4 P5 P2 P5 P2 P5
Gantt chart
P1 P2 P3 P1 P4 P5 P2 P5 P2 P5
0 2 4 6 8 9 11 13 15 16 18
Time Quantum = 2 ms Unit of Time: milliseconds
P.No AT BT CT TAT WT
P1 0 4 8 8 4
P2 1 5 16 15 10
P3 2 2 6 4 2
P4 3 1 9 6 5
P5 4 6 18 14 8
Total Time 18 57 47 29
= 47/3
= 15.66 ms
= 29/3
= 9.66 ms
Foreground–RR
Background – FCFS
Multilevel queue scheduling algorithm with five queues, listed below in order of priority.
1. System processes
2. Interactive Processes
3. Interactive editing processes
4. Batch Processes
5. Student Processes.
If a process uses too much CPU time, it will be moved to a lower-priority queue. This
scheme leaves I/O bound & interactive process in the higher priority queue. In addition, a
process that waits too long in a lower-priority queue may be moved to a higher priority
queue. This form of aging prevents starvation.
References:
[1] Operating System Principles – Abraham Silberschatz, Peter Baer Galvin, Greg
Gagne, 8th edition, Wiley-India.
[2 ] Operating Systems, I. Chandra Mohan, PHI, 2013
[3 ] http://www.tutorialspoint.com/operating_system/
[4] http://courses.cs.vt.edu/~csonline/OS/Lessons/index.html
[5] http://www.nptel.ac.in