# 1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases.

## Presentation on theme: "1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases."— Presentation transcript:

1 First Come, First Served (FCFS) The simplest algorithm –When a process becomes ready, it enters the FIFO queue. –When the currently-running process ceases to execute, the oldest process in the queue is selected for running. Non-preemptive CPU FIFO Ready Queue dispatched

2 ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec 05101520 P1 P2 P3 P4 P5

3 The average waiting time is not minimal and varies substantially if the process execution times vary. ex 1 ProcessArrival TimeProcess Exec Time P1024 msec P213 msec P323 msec –Calculate the average waiting time, turnaround time and throughput. ex 2 ProcessArrival TimeProcess Exec Time P203 msec P313 msec P1224 msec –Calculate the average waiting time, turnaround time and throughput.

4Exercises ProcessArrival TExec Time P1024 msec P213 msec P323 msec 024 P1 P2 P3 ProcessArrival TExec Time P203 msec P313 msec P1224 msec 2730 Waiting time = (0 + 23 + 25) / 3 = 16 sec Turnaround t = (24 + 26 + 28) / 3 = 26 sec Throughput = 3/30 = 0.1 03 P2 P3 P1 30 6 Waiting time = (0 + 2 + 4) / 3 = 2 sec Turnaround t = (3 + 5 + 28) / 3 = 14.3 sec Throughput = 3/30 = 0.1

5 Normalized turnaround time –The ratio of turnaround time to process exec time. –A relative delay experienced by a process The longer process exec time, the greater absolute amount of tolerable delay. ex 1 ProcessArrival TimeProcess Exec Time P1024 msec P213 msec P323 msec ex 2 ProcessArrival TimeProcess Exec Time P203 msec P313 msec P1224 msec –Calculate the turnaround time and the normalized turnaround time for each process.

6Exercises ProcessArrival TExec Time P1024 msec P213 msec P323 msec 024 P1 P2 P3 ProcessArrival TExec Time P203 msec P313 msec P1224 msec 2730 Waiting time = (0 + 23 + 25) / 3 = 16 sec Turnaround t = (24 + 26 + 28) / 3 = 26 sec NT = 24/24 + 26/3 + 28/3 = 1 + 8.6 + 9.3 = 18.9 sec Throughput = 3/30 = 0.1 03 P2 P3 P1 30 6 Waiting time = (0 + 2 + 4) / 3 = 2 sec Turnaround t = (3 + 5 + 28) / 3 = 12 sec NT = 3/3 + 5/3 + 28/24 = 1 + 1.6 + 1.1 = 3.7 sec Throughput = 3/30 = 0.1

7 The normalized turnaround times for P2 and P3 are intolerable. –This problem occurs whenever a short-lived process arrives right after a long-lived process. When the variance of process exec time is high, FCFS penalizes short processes. –FCFS is not a fair scheduling algorithm; it does not treat long-lived and short-lived processes equally.

8 TNT 3-0 = 33/3=1… 9-2=77/6=1… 13-4=77/4=1… 18-6=1212/5=2… 20-8=1212/2=6 Avg TAvg NT 8.602.56 ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec 05101520 P1 P2 P3 P4 P5

9 Round Robin Clock-based preemption of process (time slicing) –When a clock interrupt occurs, the currently-running process is placed in the end of the Ready queue, and the next ready process is executed. –A straightforward way to reduce the penalty that short-lived processes suffer with FCFS. A fairer algorithm than FCFS CPU Ready Queue FIFO and Circular Queue dispatched timeout

10 A Key Design Issue in RR How to determine the length of time quantum (time slice)? –If it’s too short, Processing overhead becomes high to handle clock interrupts and perform context switches. –(the time to handle a clock interrupt and perform a context switch) / (time quantum) should be small enough. –If it’s too long, RR degenerates to FCFS.

11 Exercise 1 ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec 05101520 P1 P2 P3 P4 P5 RR tq=1

12 ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec 05101520 P1 P2 P3 P4 P5 RR tq=1

13 ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec 05101520 P1 P2 P3 P4 P5 RR tq=1 TNT 4-0 = 44/3=1… 18-2=1616/6=2… 17-4=1313/4=3… 20-6=1414/5=2… 15-8=77/2=3.5 Avg TAvg NT 10.82.71

14 P1 P2 P3 P4 P5 05101520 FCFS ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec 05101520 P1 P2 P3 P4 P5 RR tq=1 TNT 4-0 = 44/3=1… 18-2=1616/6=2… 17-4=1313/4=3… 20-6=1414/5=2… 15-8=77/2=3.5 Avg TAvg NT 10.82.71 TNT 3-0 = 33/3=1… 9-2=77/6=1… 13-4=77/4=1… 18-6=1212/5=2… 20-8=1212/2=6 Avg TAvg NT 8.602.56 17 context switches

15 Exercise 2 ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec P1 P2 P3 P4 P5 RR tq=4 05101520 Avg process exec time = 4 msec

16 ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec P1 P2 P3 P4 P5 RR tq=4 05101520

17 ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec 05101520 P1 P2 P3 P4 P5 RR tq=1 P1 P2 P3 P4 P5 RR tq=4 05101520 TNT 4-0 = 44/3=1… 18-2=1616/6=2… 17-4=1313/4=3… 20-6=1414/5=2… 15-8=77/2=3… Avg TAvg NT 10.82.71 TNT 3-0 = 33/3=1 17-2=1515/6=2… 11-4=77/4=1… 20-6=1414/5=2… 19-8=1111/2=5.5 Avg TAvg NT 102.71 6 context switches 17 context switches

18 Exercise 3 ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec 05101520 P1 P2 P3 P4 P5 RR tq=6

19 ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec 05101520 P1 P2 P3 P4 P5 RR tq=6

20 P1 P2 P3 P4 P5 05101520 FCFS ProcessArrival TimeProcess Exec Time 103 msec 226 msec 344 msec 465 msec 582 msec 05101520 P1 P2 P3 P4 P5 RR tq=6

21 Time Quantum Should be slightly longer than typical process execution time Should be shorter than the longest process exec time. Generally 10 to 100 msec

22 Another Fairness Issue RR treats long-lived and short-lived processes equally. However, it does not treat CPU-bound and I/O- bound processes equally. –CPU-bound process Mainly performs computational work and occasionally uses I/O devises –I/O-bound process spends more time using I/O devises than using the CPU.

23 I/O-bound processes use less CPU time than CPU-bound processes. –An I/O-bound process uses for a short period and then is blocked for an I/O operation. It returns to the Ready queue when the I/O operation is completed. –A CPU-bound process uses a complete time quantum and returns to the Ready queue. CPU Ready Queue admitted dispatched exit interrupted I/O type 1 wait I/O 1 completed I/O 1 Blocked Queue I/O N Blocked Queue I/O type N wait I/O N completed CPU-bound processes tend to use more CPU time, which leads to poor performance in I/O-bound processes.

24HW Read Paper #1 (see the course web site), and summarize how the proposed scheduling algorithm addresses this fairness issue. –Use a queuing diagram in your explanation.

Similar presentations