Skip to content

05 - Process Scheduling

Briefly describe the difference between the long-term scheduler and short-term (CPU) scheduler.

Instructor Solution

The long-term scheduler (or job scheduler) determines which programs are admitted into the system for processing. It selects processes from a “job pool” on the disk and loads them into memory, thereby controlling the degree of multiprogramming (the number of processes in memory).

The short-term scheduler (or CPU scheduler) is much faster and more frequent. It selects which process, from those already residing in memory and in the “ready” state, should be executed next by the CPU. Its primary goal is to optimize system performance based on criteria like throughput and latency.

List 4 events that might occur to cause the kernel to context switch from one user process to another.

Instructor Solution

A kernel will trigger a context switch from one user process to another when:

  • I/O Completion: The I/O request of a process in Waiting (Blocked) state completes and the process moves from the Blocked state to the Ready state.
  • I/O Request: A process makes an I/O request for a slow resource (like reading from a disk), causing it to move from a Running to a Blocked state.
  • Time-Slice Expiration: In preemptive multitasking, the CPU scheduler decides the process has used its allotted time (quantum) and forces a switch.
  • New Process Arrival: A new process with a higher priority arrives and the OS decides to stop the currently executing process and schedule the newly arrived process.
  • Process Termination: The current process finishes its execution or crashes, requiring the kernel to select a new process to run.

Problem 3: Preemptive vs. Non-Preemptive Scheduling

Section titled “Problem 3: Preemptive vs. Non-Preemptive Scheduling”

What’s the difference between preemptive and non-preemptive scheduling? Briefly explain. Which one is more suitable for a timesharing system?

Instructor Solution

In non-preemptive scheduling, a process keeps the CPU until it either terminates or voluntarily switches to a waiting state (e.g., for I/O). The kernel cannot force it to stop. In preemptive scheduling, the kernel can interrupt a running process at any time to give the CPU to another process, usually based on a timer interrupt or the completion of an I/O request for process with a higher priority.

Preemptive scheduling is more suitable for a timesharing system. This is because timesharing requires the OS to rapidly cycle through multiple users/processes to ensure that everyone receives a responsive experience, which is only possible if the OS can force processes to yield the CPU after their time slice (quantum) expires.

Problem 4: Context Switch State Preservation

Section titled “Problem 4: Context Switch State Preservation”

What state is saved on a context switch between threads of the same process?

Instructor Solution

When the kernel performs a context switch between threads of the same process, it must save the Thread Context, which consists of:

  • Program Counter (PC): The memory address of the next instruction to execute.
  • CPU Registers: The current state of general-purpose and floating-point registers.
  • Stack Pointer (SP): The location of the thread’s private stack (containing local variables and function calls).

Crucially, because threads share the same address space, the kernel does not need to save or reload memory management information like page tables or the heap.

Selecting a proper time quantum is important in round robin scheduling. What happens if the quantum is too big? What happens if it is too small? Briefly explain.

Instructor Solution

In Round Robin scheduling, the time quantum determines the system’s balance between efficiency and responsiveness:

  • If the quantum is too big: The algorithm behaves like First-Come, First-Served (FCFS). Long processes will monopolize the CPU, causing “convoy effects” where short, interactive tasks must wait a long time, leading to poor responsiveness in a multi-user or UI-driven system.
  • If the quantum is too small: The system suffers from excessive overhead. Because the CPU spends a higher percentage of its time performing context switches (saving and loading process states) rather than executing actual instructions, the overall system throughput drops significantly.

What’s starvation as it applies to process scheduling? In which scheduling discipline is it more likely to occur? Give an example.

Instructor Solution

Starvation occurs when a process is perpetually denied CPU time because higher-priority processes are constantly being scheduled ahead of it. The process remains in the “Ready” state indefinitely, even though it is technically capable of running. It is most likely to occur in Priority Scheduling (specifically Fixed-Priority) and Shortest Job First (SJF).

Example: In a system that always executes the shortest task first, a very long process might never run if new, short processes continue to arrive every few seconds. The long process “starves” while the CPU handles a never-ending stream of quick tasks or tasks with higher priority.

A friend of yours is to design an OS that would run batch jobs, and s/he decides to employ Round Robin Scheduling algorithm. Is your friend making a good choice. Why or why not?

Instructor Solution

No, Round Robin is generally a poor choice for a pure batch system. Batch jobs are typically long-running, non-interactive tasks where the primary goal is maximum throughput and efficiency. Round Robin introduces frequent context-switching overhead and interrupts long-running processes unnecessarily. For batch processing, First-Come, First-Served (FCFS) or Shortest Job First (SJF) are better because they minimize overhead and complete individual jobs faster.

Problem 8: Ready to Waiting State Transition

Section titled “Problem 8: Ready to Waiting State Transition”

Is it possible for a process to move from the Ready state to the Waiting (blocked) state? Why or why not? Briefly justify your answer.

Instructor Solution

No, a process cannot move directly from the Ready state to the Waiting (Blocked) state. Justification: A process only enters the Waiting state when it requests a resource (like an I/O operation) that isn’t immediately available. To make such a request, the process must execute a system call, which requires the CPU. Since a process in the Ready state is not currently executing on the CPU, it cannot perform the actions necessary to block itself. It must first be scheduled to the Running state.

In Round-Robin scheduling, new processes are placed at the end of the queue, rather than at the beginning. Suggest a reason for this.

Instructor Solution

This design ensures Fairness and prevents Starvation. By placing new processes at the end of the queue, the system follows a First-In-First-Out (FIFO) logic that guarantees every process already in the “Ready” state gets its allotted time slice before a newcomer can “cut the line.” If new processes were placed at the beginning, a constant stream of incoming tasks could indefinitely postpone the execution of existing ones leading to starvation.

Explain why Round-Robin scheduling tends to favor CPU bound processes over I/O bound ones.

Instructor Solution

Round-Robin favors CPU-bound processes because they typically use their entire time quantum, allowing them to maximize their CPU occupancy and stay at the front of the scheduler’s mind once their turn returns. I/O-bound processes, conversely, often execute for only a fraction of their quantum before blocking for I/O. When they finish their I/O and return to the Ready queue, they are placed at the back of the line, effectively “losing” the remainder of their unused time. This results in I/O-bound processes getting significantly less total CPU time relative to their needs compared to CPU-heavy tasks.

CPU scheduling quanta have remained about the same over the past 20 years, but processors are now over 1,000 times faster. Why has CPU scheduling quanta NOT changed?

Instructor Solution

The reason CPU scheduling quanta have remained largely unchanged (typically between 10ms and 100ms) despite processors becoming 1,000 times faster is that the quantum is determined by human perception, not processor speed. A quantum is designed to be short enough to create the illusion of concurrency for a human user—making the system feel “responsive”—but long enough so that the context switch overhead (the time spent saving/loading process states) remains a negligible fraction of the total execution time. While a modern CPU can execute many more instructions within that 100ms window than a CPU from 20 years ago, reducing the quantum further would:

  1. Not improve the user experience, as humans cannot perceive sub-millisecond responsiveness.
  2. Increase overhead, because the time required to perform a context switch (governed by memory and bus speeds) has not decreased as dramatically as raw CPU calculation speed.

Briefly explain how the shortest job first scheduling works.

Instructor Solution

Shortest Job First (SJF) scheduling selects the process with the smallest next CPU burst length from the Ready Queue to execute next. If two processes have the same burst length, First-Come, First-Served (FCFS) is typically used to break the tie. SJF is mathematically optimal for minimizing the average waiting time for a given set of processes because it moves short jobs to the front, clearing them out of the system quickly. There are two versions:

  1. Non-preemptive: Once a process starts, it holds the CPU until it finishes its burst.
  2. Preemptive (Shortest Remaining Time First): If a new process arrives with a shorter burst than the remaining time of the current process, the CPU is switched to the new process

Briefly explain multi-level feedback queuing scheduling algorithm.

Instructor Solution

Multilevel Feedback Queue (MLFQ) scheduling uses multiple queues with different priority levels to categorize processes based on their CPU-burst behavior. New processes enter the highest-priority queue and are granted a short time quantum. If a process uses its entire quantum (CPU-bound), it is demoted to a lower-priority queue with a longer quantum. If a process blocks for I/O (I/O-bound), it stays at or moves to a higher-priority queue. This dynamically separates interactive tasks from background batch jobs, optimizing both responsiveness and throughput.

Problem 14: Optimal Scheduling for Maximum Throughput

Section titled “Problem 14: Optimal Scheduling for Maximum Throughput”

Consider a set of “n” tasks with known burst times to be run on a uniprocessor machine. Which scheduling algorithm will result in the maximum throughput, i.e., minimum average turnaround time. Justify your answer.

Instructor Solution

The algorithm that results in the minimum average turnaround time (and thus high throughput) is Shortest Job First (SJF). Average turnaround time is minimized when the shortest tasks are completed first. By scheduling the smallest burst time at the earliest possible moment, we ensure that the waiting time for all subsequent processes is kept to a minimum. Mathematically, this moves the “waiting” cost of long jobs to the end of the schedule, preventing them from delaying a large number of smaller tasks.

True/False: Shortest Remaining Time First scheduling may cause starvation. Justify your answer.

Instructor Solution

True. Shortest Remaining Time First (SRTF) is the preemptive version of SJF. If a steady stream of new processes with very short burst times keeps arriving, a process with a long burst time will be constantly preempted or bypassed. It will remain in the Ready queue indefinitely, unable to finish its execution, which is the definition of starvation.

Problem 16: Preemptive Priority and Starvation

Section titled “Problem 16: Preemptive Priority and Starvation”

True/False: Preemptive Priority scheduling may cause starvation. Justify your answer.

Instructor Solution

True. In Preemptive Priority scheduling, the kernel always grants the CPU to the process with the highest priority. If the system is constantly flooded with high-priority tasks, a low-priority process will be repeatedly preempted or bypassed. It may sit in the Ready queue indefinitely, never receiving enough CPU time to complete.

Problem 17: Round Robin vs. FCFS Response Time

Section titled “Problem 17: Round Robin vs. FCFS Response Time”

True/False: Round Robin scheduling is better than FCFS in terms of response time. Justify your answer.

Instructor Solution

True. Round Robin is designed specifically to improve response time by limiting how long any single process can hold the CPU. In FCFS, a short process can be stuck behind a very long one (the “convoy effect”), leading to long delays. Round Robin ensures that every process gets a turn within a fixed time window, providing much faster initial feedback to users.

Problem 18: FCFS Gantt Chart with 5 Processes

Section titled “Problem 18: FCFS Gantt Chart with 5 Processes”

Consider the following 5 processes in a system.

ProcessArrival TimeBurst Time
P145
P264
P303
P462
P554

Draw a Gantt chart illustrating the execution of these processes using FCFS. Compute the average waiting time and average turnaround time. What’s the CPU utilization?

Instructor Solution

Gantt Chart:

P3IdleP1P5P2P4
0349131719

Process Metrics:

ProcessArrival TimeBurst TimeFinish TimeTurnaroundWaiting Time
P145950
P26417117
P303330
P462191311
P5541384

Average Waiting Time = (0 + 7 + 0 + 11 + 4) / 5 = 4.4

Average Turnaround Time = (5 + 11 + 3 + 13 + 8) / 5 = 8

CPU Utilization =

Consider the following 6 processes in a system.

ProcessArrival TimeBurst Time
P103
P212
P321
P434
P545
P652

(a) Draw a Gantt chart illustrating the execution of these processes using FCFS. Compute the average waiting time and average turnaround time for each case.

Instructor Solution

Gantt Chart:

P1P2P3P4P5P6
0356101517

Process Metrics:

ProcessArrival TimeBurst TimeFinish TimeTurnaroundWaiting Time
P103330
P212542
P321643
P4341073
P54515116
P652171210

Average Waiting Time = (0 + 2 + 3 + 3 + 6 + 10) / 6 = 4

Average Turnaround Time = (3 + 4 + 4 + 7 + 11 + 12) / 6 = 6.83

(b) Now assume that there is 1 unit of overhead when scheduling a process. Compute the efficiency of the scheduling algorithm; that is, the percentage of time where the CPU is doing useful work as opposed to doing context switching.

Instructor Solution

With 1 unit of scheduling overhead between each process transition, there will be 5 units of scheduling overhead total (between P1→P2, P2→P3, P3→P4, P4→P5, P5→P6). Total time = 17 + 5 = 22.

CPU Efficiency = (17 / 22) × 100 = 77.27%

The CPU is doing useful work 77.27% of the time.

Problem 20: Preemptive SRTF with 4 Processes

Section titled “Problem 20: Preemptive SRTF with 4 Processes”

Consider the following 4 processes in a system.

ProcessArrival TimeBurst Time
P1012
P224
P336
P481

Draw a Gantt chart illustrating the execution of these processes using preemptive shortest remaining time first algorithm. Compute the average waiting time and average turnaround time.

Instructor Solution

Gantt Chart:

P1P2P3P1P3
02681723

Process Metrics:

ProcessArrival TimeBurst TimeFinish TimeTurnaroundWaiting Time
P101217175
P224640
P336232014
P481910

Average Waiting Time = (5 + 0 + 14 + 0) / 4 = 4.75

Average Turnaround Time = (17 + 4 + 20 + 1) / 4 = 10.5

Problem 21: Preemptive SRTF with Different Arrivals

Section titled “Problem 21: Preemptive SRTF with Different Arrivals”

Consider the following 4 processes in a system.

ProcessArrival TimeBurst Time
P1010
P236
P371
P483

Draw a Gantt chart illustrating the execution of these processes using preemptive shortest remaining time first algorithm. Compute the average waiting time and average turnaround time.

Instructor Solution

Gantt Chart:

P1P2P3P2P4P1
0337 83 10 141 20

Process Metrics:

ProcessArrival TimeBurst TimeFinish TimeTurnaroundWaiting Time
P1010202010
P2361071
P371810
P4831463

Average Waiting Time = (10+1+0+3) / 4 = 3.5

Average Turnaround Time = (20+7+1+6) / 4 = 8.5

Problem 22: Priority Scheduling Non-preemptive vs. Preemptive

Section titled “Problem 22: Priority Scheduling Non-preemptive vs. Preemptive”

Consider the following 5 processes in a system. Assume that lower values indicate higher priority.

ProcessArrival TimeBurst TimePriority
P10112
P25280
P31223
P42101
P59164

(a) Draw the Gantt chart if we employ non-preemptive priority scheduling. Compute the turnaround time for each process.

Instructor Solution

Process diagram

Process Metrics:

ProcessArrival TimeBurst TimeFinish TimeTurnaround
P10111111
P25283934
P31224937
P42105149
P59166758

(b) Draw the Gantt chart if we employ preemptive priority scheduling. Compute the turnaround time for each process.

Instructor Solution

Process Metrics:

ProcessArrival TimeBurst TimeFinish TimeTurnaround
P10114949
P25283327
P31225139
P42104038
P59166758

Problem 23: Priority Scheduling with Higher Priority Values

Section titled “Problem 23: Priority Scheduling with Higher Priority Values”

Consider the following 5 processes in a system. Assume that higher values indicate higher priority.

ProcessArrival TimeBurst TimePriority
P1042
P2133
P3214
P4355
P5425

(a) Draw the Gantt chart if we employ non-preemptive priority scheduling. Compute the turnaround time for each process.

Instructor Solution

Process Metrics:

ProcessArrival TimeBurst TimeFinish TimeTurnaround
P10444
P2131514
P3211210
P43596
P542117

(b) Draw the Gantt chart if we employ preemptive priority scheduling. Compute the turnaround time for each process.

Instructor Solution

Process Metrics:

ProcessArrival TimeBurst TimeFinish TimeTurnaround
P1041515
P2131211
P32131
P43585
P542106

Consider the following 5 processes in a system.

ProcessArrival TimeBurst Time
P105
P213
P321
P432
P543

Draw a Gantt chart illustrating the execution of these processes using round robin scheduling with a quantum of 2. Compute the average waiting time and average turnaround time. Note: At any given time, a newly arriving process is put to the back of the ready queue before the executing process is preempted. That is, the preempted process is always the last process in the ready queue.

Instructor Solution

Gantt Chart:

P1P2P3P1P4P5P2P1P5
0224579111

Process Metrics:

ProcessArrival TimeBurst TimeFinish TimeTurnaroundWaiting Time
P10513138
P21312118
P321532
P432964
P54314107

Average Waiting Time = (8+8+2+4+7) / 5 = 5.8

Average Turnaround Time = (13+11+3+6+10) / 5 = 8.6

Consider the following 3 processes in a system.

ProcessArrival TimeBurst Time
P105
P217
P334

Draw a Gantt chart illustrating the execution of these processes using FCFS and round robin scheduling with a quantum of 2. Compute the average waiting time and average turnaround time.

(a) FCFS

Instructor Solution

Process diagram

Process Metrics:

ProcessArrival TimeBurst TimeFinish TimeTurnaroundWaiting Time
P105550
P21712114
P33416139

Average Waiting Time = (0+4+9) / 3 = 4.33

Average Turnaround Time = (5+11+13) / 3 = 9.66

(b) Round Robin with quantum of 2

Instructor Solution

Process diagram

Process Metrics:

ProcessArrival TimeBurst TimeFinish TimeTurnaroundWaiting Time
P10511116
P21716158
P33413106

Average Waiting Time = (6+8+6) / 3 = 6.66

Average Turnaround Time = (11+15+10) / 3 = 12

Consider the following function named “Work”, which performs I/O for 1 time unit and then performs computation for 1 time unit within a loop.

void Work(int numOfIterations){
for (int i=0; i < numOfIterations; i++){
DoIO(); // I/O takes 1 time unit
Compute(); // Computation takes 1 time unit
} //end-for
} //end-Work
main1(int argc, char *argv[]){
Work(10); // Do the work in a single-threaded process
} //end-main
main2(int argc, char *argv[]){
CreateThread(Work(5)); // Create a thread to run Work with numOfIterations = 5
CreateThread(Work(5)); // Create a thread to run Work with numOfIterations = 5
wait_until_both_threads_are_done();
} //end-main

(a) Assume that the OS does NOT support threads. So the programmer designs its main function to be single-threaded and codes main1() shown above. Assuming that this is the only process in the system and the machine has 1 CPU, how long does the program take to finish? Answer the same question when the machine has 2 CPUs.

Instructor Solution
Time1234567891011121314151617181920
CPUT1T1T1T1T1T1T1T1T1T1
I/OT1T1T1T1T1T1T1T1T1T1

It takes 20 units of time for the process (T1) to finish executing. If we had 2 CPUs, T1 would still have taken 20 units of time because the second CPU would have to stay idle as there is only one thread to execute in the system.

(b) Assume now that the OS supports kernel-level threads. So the programmer designs its main function to be multi-threaded and codes main2() shown above. Assuming that this is the only process in the system and the machine has 1 CPU, how long does the program take to finish? Answer the same question when the machine has 2 CPUs. Assume that the threads can NOT perform I/O in parallel.

Instructor Solution
Time1234567891011
CPUT1T2T1T2T1T2T1T2T1T2
I/OT1T2T1T2T1T2T1T2T1T2

T1 finishes at time 10 and T2 finishes at time 11. So, the program finishes at time 11.

If we have two CPUs, we can theoretically schedule both T1 and T2 in parallel, but because both T1 and T2 are using the same I/O device and I/O can NOT be performed in parallel, we will get the same schedule and the program will still finish at time 11. Notice that one the CPUs will still be idle as at any point in time, only one of the threads is ready to execute while the other is doing I/O.

Consider the following two threads T1 and T2 that belong to the same process P. Assume T1 is created first, followed by T2. Further assume that there is a single I/O device, which means that parallel I/O is NOT possible.

T1T2
Compute(5)Compute(3)
I/O(3)I/O(6)
Compute(5)Compute(1)
I/O(3)I/O(5)
Compute(2)Compute(4)

Assume that threads T1 and T2 are implemented as kernel threads. Draw the Gantt chart for First Come First Served (FCFS) scheduling. Compute the turnaround time for T1 and T2. Also compute the CPU utilization.

Instructor Solution

Process diagram

Process Metrics:

ProcessArrival TimeFinish TimeTurnaround
T101919
T202626

CPU Utilization:

Two processes A and B execute the program given below. That is, each process performs computation for 3 units of time and performs I/O for 2 units of time within a loop.

main(int argc, char *argv[]){
for (int i=0; i < 2; i++){
Compute(); // Computation takes 3 time units
DoIO(); // I/O takes 2 time units
} //end-for
} //end-main

Assume that both processes are ready at time 0. Assume a single CPU and one I/O device. Assume that I/O can NOT be performed in parallel. Show the Gantt chart for the processes and compute the CPU utilization, and average turnaround time under:

(a) FIFO Scheduling algorithm.

Instructor Solution
Time1234567891011121314151617181920
CPUAAABBBAAABBB
I/OAABBAABB

Process Metrics:

ProcessArrival TimeFinish TimeTurnaround
A01111
B01414

CPU Utilization: $\frac{12}{14} \times 100 = 85.71%

(b) Round-robin scheduling algorithm with a time quanta of 1 unit.

Instructor Solution
Time1234567891011121314151617181920
CPUABABABAABABB
I/OAABBAABB

Process Metrics:

ProcessArrival TimeFinish TimeTurnaround
A01313
B01515

CPU Utilization: $\frac{12}{15} \times 100 = 80%

Problem 29: Exploiting Scheduling Policies

Section titled “Problem 29: Exploiting Scheduling Policies”

Given a scheduling strategy, you can find a way to exploit the policy to your advantage and detriment other users. For each scheduling policy below, describe how you can exploit the scheduling policy to your advantage. For all cases, assume we are using a multi-level feedback queue that does round-robin scheduling within each priority level.

(a) Policy 1: Any job that uses an entire scheduling quantum is dropped to the next lowest priority level. The idea of this policy is to penalize compute-bound jobs.

Instructor Solution

The idea is to use the whole quanta except an epsilon time unit and call Yield() to give up the CPU. This way your priority will never decrease.

(b) Policy 2: Any process that performs an I/O operation during its scheduling quantum is moved up to the next highest priority level. The idea is to award I/O bound processes.

Instructor Solution

The idea is to make an I/O such as printing a char on the screen within a time quantum. This will increase your priority and you will be scheduled more often.

Problem 30: Priority Scheduling with 4 Processes

Section titled “Problem 30: Priority Scheduling with 4 Processes”

Consider the following 4 processes in a system. Assume that lower values indicate higher priority.

ProcessArrival TimeBurst TimePriority
P1054
P2233
P3452
P41121

(a) Draw the Gantt chart if we employ non-preemptive priority scheduling. Compute the turnaround time for each process.

Instructor Solution

Process Metrics:

ProcessArrival TimeFinish TimeTurnaround
P1055
P221311
P34106
P411154

(b) Draw the Gantt chart if we employ preemptive priority scheduling. Compute the turnaround time for each process.

Instructor Solution

Process Metrics:

ProcessArrival TimeFinish TimeTurnaround
P101515
P22108
P3495
P411132

Problem 31: Priority Scheduling with 5 Processes

Section titled “Problem 31: Priority Scheduling with 5 Processes”

Consider the following 5 processes in a system. Assume that lower values indicate higher priority.

ProcessArrival TimeBurst TimePriority
P1064
P2263
P3432
P4931
P51335

(a) Draw the Gantt chart if we employ non-preemptive priority scheduling. Compute the turnaround time for each process.

Instructor Solution

Process Metrics:

ProcessArrival TimeFinish TimeTurnaround
P1066
P221816
P3495
P49123
P513218

(b) Draw the Gantt chart if we employ preemptive priority scheduling. Compute the turnaround time for each process.

Instructor Solution

Process Metrics:

ProcessArrival TimeFinish TimeTurnaround
P101818
P221412
P3473
P49123
P513218

Problem 32: Multiple Scheduling Algorithms Comparison

Section titled “Problem 32: Multiple Scheduling Algorithms Comparison”

Consider the following 5 processes in a system.

ProcessArrival TimeBurst Time
P103
P215
P332
P495
P5125

Draw 4 Gantt charts illustrating the execution of these processes using FCFS, SJF, and a RR (quantum=1) scheduling. Compute the average turnaround time for each case. Note: At any given time, a newly arriving process is put to the back of the ready queue before the executing process is preempted. That is, the preempted process is always the last process in the ready queue.

(a) FCFS

Instructor Solution

Process diagram

Process Metrics:

ProcessArrival TimeFinish TimeTurnaround
P1033
P2187
P33107
P49156
P512208

Average Turnaround Time = (3+7+7+6+8) / 5 = 6.2

(b) SJF

Instructor Solution

Process diagram

Process Metrics:

ProcessArrival TimeFinish TimeTurnaround
P1033
P21109
P3352
P49156
P512208

Average Turnaround Time = (3+9+2+6+8) / 5 = 5.6

(c) RR with quantum = 1

Instructor Solution
Time1234567891011121314151617181920
CPUP1P2P1P2P3P1P2P3P2P4P2P4P5P4P5P4P5P4P5P5

Process Metrics:

ProcessArrival TimeFinish TimeTurnaround
P1066
P211110
P3385
P49189
P512208

Average Turnaround Time = (6+10+5+9+8) / 5 = 7.6

Problem 33: SJF, Priority, and RR Comparison

Section titled “Problem 33: SJF, Priority, and RR Comparison”

Consider the following set of processes with the given CPU burst times and priorities.

ProcessBurst TimePriority
P1103
P211
P323
P414
P552

The processes have arrived in order from P1 to P5 all at time 0. Draw 4 Gantt charts illustrating the execution of these processes using SJF, priority (a smaller priority number implies a higher priority), and RR (quantum=1) scheduling. For each scheduling algorithm, compute the turnaround time and the waiting time for each process.

(a) SJF

Instructor Solution

Process diagram

Process Metrics:

ProcessBurst TimeFinish TimeTurnaroundWaiting Time
P11019199
P21110
P32442
P41221
P55994

(b) Priority Scheduling

Instructor Solution

Process diagram

Process Metrics:

ProcessBurst TimeFinish TimeTurnaroundWaiting Time
P11016166
P21110
P32181816
P41191918
P55661

(c) RR with quantum = 1

Instructor Solution

Process diagram

Process Metrics:

ProcessBurst TimeFinish TimeTurnaroundWaiting Time
P11019199
P21221
P32775
P41443
P5514149

Problem 34: CPU and I/O Scheduling with FCFS and RR

Section titled “Problem 34: CPU and I/O Scheduling with FCFS and RR”

Consider the following set of processes with the given CPU, I/O burst times. The processes are assumed to have arrived in the order P1, P2, P3 all at time 0. Assume that the I/O operations can NOT be performed in parallel. That is, if a process is doing I/O, other processes must wait until the current process finishes its I/O operation. I/O scheduler uses FIFO scheduling.

P1P2P3
5 CPU10 CPU2 CPU
17 I/O4 I/O3 I/O
3 CPU10 CPU6 CPU

(a) Draw a Gantt chart illustrating the execution of these processes using FCFS. Compute the turnaround for each process, and the CPU utilization.

Instructor Solution

Process diagram

CPU Utilization:

Process Metrics:

ProcessArrival TimeFinish TimeTurnaround
P102525
P203636
P304242

(b) Draw a Gantt chart illustrating the execution of these processes using Round Robin Scheduling with a time quanta of 4. Compute the average waiting time and CPU utilization.

Instructor Solution

Process diagram

CPU Utilization:

Process Metrics:

ProcessArrival TimeFinish TimeTurnaround
P103333
P204444
P302323

Problem 35: Multi-Algorithm Comparison with I/O

Section titled “Problem 35: Multi-Algorithm Comparison with I/O”

Consider the following set of processes with the given CPU, I/O burst times. The processes are assumed to have arrived in the order P1, P2, P3 all at time 0. Assume that the I/O operations can NOT be done in parallel. That is, if a process is doing I/O, other processes must wait until the current process finishes its I/O operation. I/O scheduler uses FIFO scheduling.

P1P2P3
2 CPU4 CPU4 CPU
3 I/O3 I/O3 I/O
1 CPU2 CPU2 CPU

(a) Draw a Gantt chart illustrating the execution of these processes using FCFS. Compute the average waiting time and CPU utilization.

Instructor Solution

alt text

CPU Utilization: 100%

(b) Draw a Gantt chart illustrating the execution of these processes using preemptive priority scheduling. Assume that P1 has the highest priority and P3 has the lowest priority. Compute the average turnaround time and CPU utilization.

Instructor Solution

alt text

CPU Utilization:

(c) Draw a Gantt chart illustrating the execution of these processes using Round Robin Scheduling with a time quanta of 2. Compute the average waiting time and CPU utilization.

Instructor Solution

alt text

CPU Utilization:

Consider the following set of processes with the given CPU, I/O burst times. The processes are assumed to have arrived in the order P1, P2, P3 all at time 0. Assume that P1 has the highest priority and P3 has the lowest priority. Assume that the I/O operations can NOT be done in parallel. That is, if a process is doing I/O, other processes must wait until the current process finishes its I/O operation. I/O scheduler uses FIFO scheduling.

P1P2P3
5 CPU10 CPU2 CPU
17 I/O4 I/O3 I/O
4 CPU10 CPU6 CPU

(a) Draw a Gantt chart illustrating the execution of these processes using Priority Scheduling without preemption. Compute the average waiting time and CPU utilization.

Instructor Solution

alt text

CPU Utilization:

(b) Draw a Gantt chart illustrating the execution of these processes using Shortest Job First with preemption, that is, Shortest Remaining Time First Scheduling. Compute the CPU utilization.

Instructor Solution

alt text

CPU Utilization:

Problem 37: SJF and Priority with Preemption

Section titled “Problem 37: SJF and Priority with Preemption”

Consider the following set of processes with the given CPU, I/O burst times. The processes are assumed to have arrived in the order P1, P2, P3 all at time 0. Assume that P1 has the highest priority and P3 has the lowest priority. Assume that the I/O operations can NOT be done in parallel. That is, if a process is doing I/O, other processes must wait until the current process finishes its I/O operation. I/O scheduler uses FIFO scheduling.

P1P2P3
5 CPU10 CPU2 CPU
17 I/O4 I/O3 I/O
4 CPU10 CPU6 CPU

(a) Draw a Gantt chart illustrating the execution of these processes using Shortest Job First without preemption. Compute the average waiting time and CPU utilization.

(b) Draw a Gantt chart illustrating the execution of these processes using Priority Scheduling with preemption. Compute the average waiting time and CPU utilization.