Professional Documents
Culture Documents
PREVIOUS SESSION
1. Interprocess communication ( IPC )
2. Introduction to threads
3. Difference between threads and process
4. Multiprocessing vs multithreading
5. Multithreading challenges
While(1) {
// code
}
Disadvantages
• Waiting time can be very high
• Convoy effect – a process with large burst time increases waiting time for
all other processes behind it
• Favors CPU bound process over IO
• Less throughput and CPU utilization
Shortest-Job-First Scheduling (SJF)
• The process with least burst time gets CPU first
• Based on burst time
• If CPU burst time is same, use FCFS.
• Nonpreemptive scheduling
MORE EXAMPLES SJF FOR PRACTICE
• https://youtu.be/h79jrm2Jkuc
• https://youtu.be/B5gR_EC2IHM
Advantages and Disadvantages
Advantages
• Easy to implement
• Shorter jobs first – less waiting time
• Higher CPU utlilization and throughput than FCFS
Disadvantages
• Can lead to starvation
• Convoy effect possible here also
• Tough to implement ( predicting next CPU burst time )
Shortest Remaining Time First (SRTF)
• Similar to SJF
• Preemptive Scheduling
MORE EXAMPLES SRTF FOR PRACTICE
• https://youtu.be/6iG_c8I97rI
• https://youtu.be/kH4Uvr6qbTI
Advantages and Disadvantages
Advantages
• Shorter jobs first – less waiting time than FCFS and SJF
• Higher CPU utlilization and throughput than FCFS and SJF
• No convoy effect
Disadvantages
• Can lead to starvation
• Tough to implement ( predicting next CPU burst time )
Nonpreemptive priority scheduling
• Similar to SJF
• Here priority is provided explicitly
• In SJF, priority -> Burst time
• Priority -> 0-127
• Which is high priority and which is low?
• Nonpreemptive scheduling
• In case priority are same, follow FCFS
MORE EXAMPLES NONPREEMPTIVE PRIORITY
FOR PRACTICE
• https://youtu.be/8MCb5S_iSjU
• https://youtu.be/3MXQ4uP0XsA
• https://youtu.be/3lGhsUYMPDc
Preemptive Priority Scheduling
• Similar to SRTF
• Priority is explicitly mentioned here
• Preemptive scheduling
MORE EXAMPLES PREEMPTIVE PRIORITY FOR
PRACTICE
• https://youtu.be/VbFyvHSxftI
• https://youtu.be/SkpB0NDYS8E
Advantages and disadvantages
Advantage
• Easy to implement
• Good for critical process
Disadvantage
• Suffers from starvation (solved using aging technique )
• Deciding priority of the process
AGING TECHNIQUE
• A priority scheduling algorithm can leave some lowpriority processes
waiting indefinitely or starved
• Rumor has it that when they shut down the IBM 7094 at MIT in 1973,
they found a low-priority process that had been submitted in 1967
and had not yet been run.
• Aging is a technique of gradually increasing the priority of processes
that wait in the system for a long time. For example, if priorities range
from 127 (low) to 0 (high), we could decrease the priority of a waiting
process by 1 every 15 minutes.
ROUND ROBIN (RR) Scheduling algorithm
• Time sharing systems
• FCFS + preemption
• Time quantum or Time slice ( 1 to 100 ms )
• Implemented using FIFO queue
RR MORE EXAMPLES FOR PRACTICE
• https://youtu.be/kfYXMbc-Tok
• https://youtu.be/1d8r3M_tVXw
Advantages and disadvantages
Advantage
• Better response time
• No starvation
• No convoy effect
Disadvantages
• Average waiting time very high
• Time slice is low -> More context switches
• Time slice is high -> Becomes more like FCFS
MULTILEVEL QUEUE SCHEDULING
• Ready queue is divided into multiple queues
• Each queue has its own scheduling algorithm
• Scheduling algorithms among queues ( priority )
• Each queue has absolute priority over lower-priority queues. No process in
the batch queue, for example, could run unless the queues for system
processes, interactive processes, and interactive editing processes were all
empty. If an interactive editing process entered the ready queue while a
batch process was running, the batch process would be preempted.
• Another possibility is to time-slice among the queues. Here, each queue
gets a certain portion of the CPU time, which it can then schedule among
its various processes. For instance, in the foreground-background queue
example, the foreground queue can be given 80 percent of the CPU time
for RR scheduling among its processes, whereas the background queue
receives 20 percent of the CPU to give to its processes on an FCFS basis.
Multilevel Feedback Queue Scheduling
• In multilevel queue scheduling, processes are permanently assigned to a
queue
• This algorithm allows processes to move between queues.
• The idea is to separate processes according to the characteristics of their
CPU bursts.
• If a process uses too much CPU time, it will be moved to a lower-priority
queue. This scheme leaves I/O-bound and interactive processes in the
higher-priority queues.
• 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.
SOLUTIONS TO GIVEN PROBLEMS
• FCFS Example -> Question 1
• SJF AND SRTF -> Question 4
• Priority scheduling -> Question 7
• Round Robin -> Question 9