CsTutorialpoint - Operating System-Unit2-Complete PDF
CsTutorialpoint - Operating System-Unit2-Complete PDF
Process Management
A process is basically a program in execution. The
execution of a process must progress in a
sequential fashion.
A process is defined as an entity which represents
the basic unit of work to be implemented in the
system.
To put it in simple terms, we write our computer
programs in a text file and when we execute this
program, it becomes a process which performs all the
tasks mentioned in the program.
When a program is loaded into the memory and it
becomes a process, it can be divided into four sections
─ stack, heap, text and data. The following image
shows a simplified layout of a process inside main
memory −
1. Stack: The process Stack contains the temporary data
such as method/function parameters, return address and
local variables.
2. Heap: This is dynamically allocated memory to a
process during its run time.
3. Text: This includes the current activity represented by
the value of Program Counter and the contents of the
processor's registers.
4. Data: This section contains the global and static
variables.
Process State
When a process executes, it passes through different
states. These stages may differ in different operating
systems, and the names of these states are also not
standardized.
TAIL HEAD
CPU takes
New
process
process
from here
added
here
It is simple scheduling algorithm.
Disadvantages
The average waiting time is often long.
Not suitable for time sharing system.
It may cause of convoy effect, where all other processes
wait for a long process to get off the CPU.
Let all the process arrive at the time 0.
averageturn around
time=(21+24+30+32)/4=26.75 ms
Waiting time for process P1=0
Waiting time for process P2=21
Waiting time for process P3=24
Waiting time for process P4=30
Averagewaiting
time=(0+21+24+30)/4=18.75 ms
This is very good CPU Scheduling algorithm.
The idea is that the job that has the smallest next cpu
burst is allocated to the CPU for execution first.
Where more than one jobs have same length of next
CPU burst the FCFS scheduling is used.
This scheduling should be known as shortest next
CPU burst rather than shortest job first.
Itis optimal cpu scheduling algorithm in connection
with waiting time.
Disadvantage
It can not be implemented for the short term scheduler
since there is no way to find the length of the next
CPU burst.
Process CPU Burst Time
P1 7
P2 5
P3 2
P3 P2 P1
0 2 7 14
Turn around time for process P1=14-0
Turn around time for process P2=7-0
Turn around time for process P3=2-0
Average turn around time =(14+7+2)/3=7.6 ms
Waiting time for process P1=14-7=7
Waiting time for process P2=7-5=2
Waiting time for process P3=2-2=0
Average waiting time=(7+2+0)/3=3 ms
In the Non Preemptive Priority scheduling, The
Processes are scheduled according to the priority
number assigned to them. Once the process gets
scheduled, it will run till the completion. Generally,
the lower the priority number, the higher is the
priority of the process. Priority can be decided based
on memory requirements, time requirements or any
other resource requirement.
If processes have equal priority then FCFS is used.
There may be a number of criteria for the priority
scheduling . It is very useful scheduling.
Disadvantage
Starvation is the major problem with priority
scheduling ie some low priority processes are waiting
indefinitely for the cpu.
Process Arrival time Burst time Priority
P1 0 5 2
P2 0 2 3
P3 0 6 1
P3 P1 P2
0 6 11 13
Turn Around time for P1=11-0
Turn Around time for P2=13-0
Turn Around time for P3=6-0
P1 P2 P3 P4 P1 P5 P6 P2 P5 P6
0 3 6 9 10 12 15 18 21 23 24
Turn Around time for P1=12-0 ie 12
Turn Around time for P2=21-1 ie 20
Turn Around time for P3=9-2 ie 7
Turn Around time for P4=10-3 ie 7
Turn Around time for P5=23-4 ie 19
Turn Around time for P6=24-6 ie 18
Average turn around time=
(12+20+7+7+19+18)/6=>13.8 ms
Waiting time for P1=12-5 => 7
Waiting time for P2= 20-6 => 14
Waiting time for P3= 7-3 =>4
Waiting time for P4= 7-1 => 6
Waiting time for P5= 19-5 => 14
Waiting time for P6= 18-4 => 14
P1 P2 P4 P1 P3
0 2 7 10 16 25
Turn Around time for P1=16-0 ie 16
Turn Around time for P2=7-2 ie 5
Turn Around time for P3=25-3 ie 22
Turn Around time for P4=10-4 ie 6
Average
Turn Around time=
(16+5+22+6)/4=>12.25 ms
Waiting time for P1=16-8 => 8
Waiting time for P2= 5-5=> 0
Waiting time for P3= 22-9 =>13
Waiting time for P4= 6-3 => 3
Disadvantages
The process can not move between queues that
provide inflexibility.
If a process that waits too long time in a lower priority
queue may cause starvation.
One of the major disadvantage of multilevel queue
scheduling is indefinite postponement of lower
priority processes. To eliminate this problem the
multilevel feedback queue allows to move processes
between queues.
Here idea is that processes are prioritized according to
the CPU time, so that I/O bound processes found
higher priority than CPU bound processes. So I/O
bound processes are put in upper queues and CPU
bound processes are put in lower queues.
Processes that wait to much time in lower
queue may be moved to higher priority
queue . This is called aging.
Aging is solution of starvation problem
Process Burst time Arrival time
P1 0 0
P2 29 19 9 0 0
P3 0 0
P4 0 0
P5 12 2 0 0
TQ=10
READY QUEUE P1 P2 P3 P4 P5 P2 P5 P2
P1 P2 P3 P4 P5 P2 P5 P2
0 10 20 23 30 40 50 52 61