Sei sulla pagina 1di 4

Preemptive SJF (Shortest Remaining Time First)

Same as SJF, but differs in the fact that preemption is allowed. When a process arrives to Request Queue, sort it in and select the SJF including the running process, possibly interrupting it (Remember: SJF schedules a new process only when the running is finished) If a new process arrives with CPU burst length less than remaining time of current executing process, preempt Yank the CPU away from the currently executing process when a higher priority process is ready. On time sharing machines, this type of scheme is required because the CPU must be protected from a run-away low priority process. Give short jobs a higher priority perceived response time is thus better.

Example 1
PROCESS P1 P2 P3 P4 Gantt chart ARRIVAL TIME 0 1 2 3 SERVICE TIME 8 4 9 5

P1
0 PROCESS P1 P2 P3 P4 1

P2

P4
5 WAIT TIME 10 1 = 9 11=0 17 2 = 15 53=2

P1
10

P3
17 26

TURN AROUND TIME 17 0 = 17 51=4 26 2 = 24 10 3 = 7

Total Wait Time 9 + 0 + 15 + 2 = 26 ms Average Waiting Time = (Total Wait Time) / (Total number of processes) 26/4 = 6.5 ms Total Turn Around Time 17 + 4 + 24 + 7 = 46 ms Average Turn Around time = (Total Turn Around Time) / (Total number of processes) 46/4 = 11.5 ms

Throughput 4 jobs/26 sec = 0.15385 jobs/sec

Example 2
PROCESS P1 P2 P3 P4 Gantt chart ARRIVAL TIME 0 2 4 5 SERVICE TIME 7 4 1 4

P1
0 PROCESS P1 P2 P3 P4

P2
2

P3
4

P2
5

P4
7

P1
11 TURN AROUND TIME 16 0 = 16 7 2=5 54=1 11 5 = 6 16

WAIT TIME 11 2 = 9 (2 2) + (11 4) = 7 44=0 75=2

Total Wait Time 9 + 7 + 0 + 2 = 18 ms Average Waiting Time = (Total Wait Time) / (Total number of processes) 18/4 = 4.5 ms Total Turn Around Time 16 + 5 + 1 + 6 = 28 ms Average Turn Around time = (Total Turn Around Time) / (Total number of processes) 28/4 = 7 ms Throughput 4 jobs/16 sec = 0.25 jobs/sec

Example 3
PROCESS P1 P2 P3 P4 ARRIVAL TIME 0 2 4 6 SERVICE TIME 7 6 1 2

Gantt chart

P1
0 PROCESS P1 P2 P3 P4

P2
2

P3
4

P2
5

P4
6

P2
8

P1
11 16

WAIT TIME 11 2 = 9 (2 2) + (5 4) + (11 6) = 6 44=0 66=0

TURN AROUND TIME 16 0 = 16 11 2 = 9 54=1 86=2

Total Wait Time 9 + 6 + 0 + 0 = 15 ms Average Waiting Time = (Total Wait Time) / (Total number of processes) 15/4 = 3.75 ms Total Turn Around Time 16 + 9 + 1 + 2 = 28 ms Average Turn Around time = (Total Turn Around Time) / (Total number of processes) 28/4 = 7 ms Throughput 4 jobs/16 sec = 0.25 jobs/sec

Round Robin Scheduling



Each process is provided a fix time to execute called quantum. Once a process is executed for given time period. Process is preempted and other process executes for given time period. Context switching is used to save states of preempted processes.

Wait time of each process is following Process Wait Time : Service Time - Arrival Time P0 P1 P2 P3 (0-0) + (12-3) = 9 (3-1) = 2 6-2) + (15-9) = 10 (9-3) + (18-12) = 12

Average Wait Time: (9+2+10+12) / 4 = 8.25

Potrebbero piacerti anche