IACSD - Pune 1 Overview 1. Process 2. Process states 3. Process Scheduling 4. Type of Schedulers. 5. Basic Concepts. 6. CPU Scheduler. a. Non-preemptive scheduling. b. Preemptive scheduling. 7. Scheduling Criteria.
2 8. Scheduling Algorithms. a. FCFS . b. SJF. c. Priority. d. Round Robin. 9. Time Quantum and Context Switch Time. 10. Any Queries ? 3 4 1. What is process ? The process is a program in execution. Its a unit of work in a system. 2. Process states New -The process is being created. Ready -The process is waiting to be assigned to a processor. Running -Instructions are Being executed. Waiting -The process is waiting for some event to occur(such as an I/O completion or reception of signal). Terminated -The process has finished execution.
New Terminated Ready Waiting Running Admitted I/O or event Completion Scheduler Dispatch Interrupt Exit I/O or Event Wait Figure 1 : Diagram of process states 3. What is process scheduling ?
When a computer is multi-programmed, it frequently has multiple processes competing for the CPU at the same time. Multiprogramming is helpful to maximize CPU utilization.
4. Type of schedulers. a. Long-term scheduling The decision to add to pool of processes to be executed. b. Mid-term scheduling The decision to add to the number of processes that are partially or fully in memory. c. Short-term scheduling Decision as to which available process will be executed. d. I/O scheduling Decision as to which processs pending request shall be handled by an available I/O device.
5. Basic Concepts A B Long CPU Burst IO Request (wait) Short CPU burst IO Request (wait) Time A spends most of his time computing, it is called compute-bound B spends most of his time waiting for I/O, it is called I/O-bound Histogram of CPU-burst Times Figure 2 : Histogram of CPU-burst Times 10 6. CPU scheduler a. Non preemptive Scheduling - picks a process to run - lets it run until it blocks, terminates or voluntary releases the CPU - after clock interrupt, resume the process that was running before b. Preemptive Scheduling - picks a process to run - after a maximum amount of some fixed time suspends it (if still running) - picks another process to run (if any available) - requires clock 11 7 . Scheduling Criteria CPU utilization keep the CPU as busy as possible
Throughput Number of processes that complete their execution per time unit Turnaround time Amount of time to execute a particular process . Response time Amount of time it takes from when a request was submitted until the start of a response (not time for output) (for time- sharing environment) Waiting time Amount of time a process has been waiting in the ready queue. Quite representative 7 . Scheduling Criteria (Contd..) 13 8. Scheduling Algorithms a. FCFS (First Come First Served) b. SJF (Shortest Job First) c. Priority Scheduling d. RR (Round Robin Scheduling) a. FCFS (First Come First Served) Is non-preemptive Process Burst Time P 1 24 P 2 3 P 3 3
Suppose that the processes arrive in the order: P 1 , P 2 , P 3 , all at the same time. The Gantt Chart for the schedule is:
Waiting time for P 1 = 0; P 2 = 24; P 3 = 27 Average waiting time: (0 + 24 + 27)/3 = 17 P 1 P 2 P 3
24 27 30 0 Suppose that the processes arrive in the order P 2 , P 3 , P 1 . The Gantt chart for the schedule is:
Waiting time for P 1 = 6;
P 2 = 0 ; P 3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case. Convoy effect short process behind long process. a. FCFS - First Come First Served (contd..) P 1 P 3 P 2
6 3 30 0 0 5 10 15 20 1 2 3 4 5 Figure 3 : FCFS working concept a. FCFS - First Come First Served (contd..) b. Shortest-Job-First (SJF) Scheduling Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time. Two schemes: Non-preemptive Once CPU given to the process it cannot be preempted until completes its CPU burst. 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). Process Arrival Time Burst Time P 1 0.0 7 P 2 2.0 4 P 3 4.0 1 P 4 5.0 4
Gantt Chart
Average waiting time = (0 + 6 + 3 + 7)/4 - 4
b. SJF (contd..) P 1 P 3 P 2
7 3 16 0 P 4
8 12 Non-Preemptive Example b. SJF (contd..) Preemptive Example Process Arrival Time Burst Time P 1 0.0 7 P 2 2.0 4 P 3 4.0 1 P 4 5.0 4
Gantt Chart
Average waiting time = (9 + 1 + 0 +2)/4 - 3
P 1 P 3 P 2
4 2 11 0 P 4
5 7 P 2 P 1
16 0 5 10 15 20 1 2 3 4 5 b. SJF (contd..) c. Priority Scheduling A priority number (integer) is associated with each process, Internal, e.g., by resource needs External, e.g., by user priority The CPU is allocated to the process with the highest priority (smallest integer highest priority). Non-preemptive or Preemptive Example Proc Arrival Burst Priority P 1 0 10 3 P 2 1 1 1 P 3 2 2 3 P 4 4 1 4 P 5 8 5 2
SJF is a priority scheduling where priority is the predicted next CPU burst time.
Problem Starvation low priority processes may never execute.
Solution Aging as time progresses increase the priority of the process. c. Priority Scheduling 23 d. Round Robin (RR) Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.
If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. Example of RR with Time Quantum = 20 Process Burst Time P 1 53 P 2 17 P 3 68 P 4 24
The Gantt chart is: P 1 P 2 P 3 P 4 P 1 P 3 P 4 P 1 P 3 P 3 0 20 37 57 77 97 117 121 134 154 162 0 5 10 15 20 1 2 3 4 5 d. Round Robin (RR) Concept 9. Time Quantum and Context Switch Time. Performance large FIFS q small q must be large with respect to context switch, otherwise overhead is too high. Typically, higher average turnaround than SJF, but better response. Any queries ? Thank you ! 28