Segment 2 (Operating System)
Segment 2 (Operating System)
Process
Process Creation
Process Termination
• The child has exceeded its usage of some of the resources that it
has been allocated. (To determine whether this has occurred, the
parent must have a mechanism to inspect the state of its
children.)
• The parent is exiting, and the operating system does not allow a
Arrival Time (AT): The time at which a process enters the ready
queue.
0 2 3 7 10 13 14
p3 p1 p5 p2 p4
Turn Around time = Exit time – Arrival time
Waiting time = Turn Around time – Burst time
P1 7 7–3=4 4–4=0
P2 13 13 – 5 = 8 8–3=5
P3 2 2–0=2 2–2=0
P4 14 14 – 5 = 9 9–1=8
P5 10 10 – 4 = 6 6–3=3
Advantages
It is simple and easy to understand.
It can be easily implemented using queue data structure.
It does not lead to starvation.
Disadvantages:
It does not consider the priority or burst time of the
processes.
It suffers from convoy effect
Shortest Job First:
• SJF Scheduling can be used in both preemptive and non-preemptive
mode.
• Preemptive mode of Shortest Job First is called as Shortest Remaining
Time First (SRTF).
• for n processes, time complexity = nlog(n)
P1 P2 P4 P1 P3
0 1 5 10 17 26
0 1 2 3 4 5 6 7 8 9 10 11 12 13 16
p4 p2 p2 p1 p2 p2 p3 p3 p5 p5 p5 p4 p4 p4
0 1 3 4 6 8 11 16
p4 p2 p1 p2 p3 p5 p4
Shortest Job First:
Advantages
SRTF is optimal and guarantees the minimum average waiting
time.
It provides a standard for other algorithms since no other
algorithm performs better than it.
Disadvantages
It can not be implemented practically since burst time of the
processes can not be known in advance.
It leads to starvation for processes with larger burst time.
Priorities can not be set for the processes.
Processes with larger burst time have poor response time.
Round Robin Scheduling:
Ready Queue:
P1, P2, P3, P1, P4, P5, P2, P6, P5, P2, P6, P5
0 2 4 6 8 9 11 13 15 17 18 19 21
p1 p2 p3 p1 p4 p5 p2 p6 p5 p2 p6 p5
Round Robin Scheduling:
Advantages
Disadvantages
It leads to starvation for processes with larger burst time as they have
to repeat the cycle many times.
Its performance heavily depends on time quantum.
Priorities can not be set for the processes.
Priority Scheduling:
Out of all the available processes, CPU is assigned to
the process having the highest priority.
In case of a tie, it is broken by FCFS Scheduling.
The waiting time for the process having the highest priority
will always be zero in preemptive mode.
The waiting time for the process having the highest priority
may not be zero in non-preemptive mode.
p1 0 4 2
p2 1 3 3
p3 2 1 4
p4 3 5 5
p5 4 2 5
0 4 9 11 12 15
p1 p4 p5 p3 p2
Priority Scheduling:
Advantages
Disadvantages
FCS is 28ms:
Another class of scheduling algorithms has been created for situations in which
processes are easily classified into different groups. For example, a common
division is made between foreground (interactive) processes and background
(batch) processes. A multilevel queue scheduling algorithm partitions the ready
queue into several separate queues .The processes are permanently assigned to
one queue, generally based on some property of the process, such as memory
size, process priority, or process type. Each queue has its own scheduling
algorithm.
For example, separate queues might be used for foreground and background
processes. The foreground queue might be scheduled by an RR algorithm, while
the background queue is scheduled by an FCFS algorithm.
Multilevel Queue Scheduling:
Problem called Starvation
Starvation
Starvation in operating system occurs when a process waits for an indefinite time to
get the resource it requires.
Solution of Starvation