Process CPUArrival Time P P2 3 0 P3 3 0 The Gantt Chart for the schedule is: Waiting time for P1 = (7-7)=0; P2 = (0-0)=0; P3 = (3-0) =3 Average waiting time: ( )/3 = 1 average waiting time P2P3P1idle
Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time. Two schemes: 1. non pre- emptive – once CPU given to the process it cannot be preempted until completes its CPU burst. 2. preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF). SJF is optimal – gives minimum average waiting time for a given set of processes. Process Arrival Time CPU P P P P SJF (non-preemptive) Waiting time: P1–(0-0)=0, P2 – (8-2)=6, P3–(7-4)=3, P4–(12-5)=7 A.W.T= = 16/4 = 4 average waiting time. P1P3P2P4
Process Arrival Time CPU P ,5,0 P ,2,0 P ,0 P ,0 SRTF (Pre-emptive) Waiting time: P1–(0-0) + (11-2)=9, P2 – (2-2) + (5-4)=1, P3–(4-4)=0, P4–(7-5)=2 A.W.T.= = 12/4 = 3 average waiting time. P1P2P3P2P4P1
A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer ≡ highest priority). 1. Preemptive 2. Non-preemptive SJF is a priority scheduling where priority is the predicted next CPU burst time. Process CPUPRI P1 72 P2 41 P3 13 P =37/3= 12 1/3 average waiting time P3P1P2P4
If Q>CPU then, CPU minus the quantum otherwise, CPU burst time in. Example :Time Quantum = 4 Process CPU Arrival Time P1 24,20,16,12,8,4,01 P2 3,00 P3 3,02 The Gantt chart is: Average waiting time = P1=(3-1)+(10-7)=2+3=5; P2=(0-0)=0; P3=(7-2)= =10/3= 3 1/3 average waiting time P2P1P3P1P1P1P1P1