Operating Systems Process Scheduling Prof. Dr. Armin Lehmann lehmann@e-technik.org Fachbereich 2 Informatik und Ingenieurwissenschaften Wissen durch Praxis stärkt Seite 1 Datum 11.04.2017
Process Scheduling If more resources within a system are requested than available, access has to be coordinated. Therefore a so called Scheduler is utilized. The Scheduler sorts the processes into the queue with some policy. We will only consider single processor machines. These machines can only handle one process after another (sequential). Seite 2
Process Scheduling In a computing system we can identify two different types of scheduling tasks: long term scheduling (job scheduling) short term scheduling (processor allocation) End of Job User Long Term Scheduling Short Term Scheduling Seite 3
Target Conflicts Each scheduling policy has certain targets, e.g.: CPU utilization optimize efficiency of utilization Throughput maximize number of jobs per time unit Fairness no job should be preferred, only if explicit set Turnaround time minimize the time a job needs from its beginning to end Waiting time minimize time a process waits in ready state list response time minimal response to user s request Seite 4
Non-preemtive Scheduling Processes run until they quit or change from active to waiting state (e.g., I/O or event) These processes will not be interrupted during running state This type of scheduling is useful only if it is known which processes are existing and which characteristics they have Seite 5
First Come First Serve (FCFS) FCFS is a very simple policy Processes will be sorted into queue as they arrive Each process will be executed no matter how long it takes Therefore a FIFO (Fist In First Out) queue is implemented This strategy has a very limited performance Seite 6
First Come First Serve (FCFS) Example: 3 jobs with length 10, 4, and 3 arrive almost at the same time Job 1 Job 2 Job 3 0 10 14 17 Turnaround time: Job 1 = 10, Job 2 = 14, Job 3 = 17, average 13.67 Job 3 Job 2 Job 1 0 3 7 17 Turnaround time: Job 3 = 3, Job 2 = 7, Job 1 = 17, average 9 Seite 7
Shortest Job First (SJF) The process that is estimated to be the shortest will be preferred This policy avoids the disadvantages coming with FCFS Interactive processes will be preferred, the mostly wait for I/O As a result the average response time will be low Problem of this policy is: If many short jobs arrive at the same time a long job may not be executed (starvation) Seite 8
Highest Response Ratio Next (HRRN) Uses the ratio of turnaround time to actual service time Values are approximated based on past history R = w+ s s R = response ratio w = time spent waiting for the processor s = expected service time Seite 9 [Stal]
Comparison of Scheduling Policies Process Arrival Time Service Time A 0 3 B 2 6 C 4 4 D 6 5 E 8 2 FCFS A B C D E Seite 10 [Stal]
Comparison of Scheduling Policies Process Arrival Time Service Time A 0 3 B 2 6 C 4 4 D 6 5 E 8 2 SJF A B C D E Seite 11 [Stal]
Comparison of Scheduling Policies Process Arrival Time Service Time A 0 3 B 2 6 C 4 4 D 6 5 E 8 2 HRRN A B C D E Seite 12 [Stal]
Comparison of Scheduling Policies Process A B C D E Arrival Time 0 2 4 6 8 Service Time (T s ) 3 6 4 5 2 Mean FCFS Finish Time 3 9 13 18 20 Turnaround Time (T t ) 3 7 9 12 12 8.60 T t /T s 1.00 1.17 2.25 2.40 6.00 2.56 SJF Finish Time 3 9 15 20 11 Turnaround Time (T t ) 3 7 11 14 3 7.60 T t /T s 1.00 1.17 2.75 2.80 1.50 1.84 HRRN Finish Time 3 9 13 20 15 Turnaround Time (T t ) 3 7 9 14 7 8.00 T t /T s 1.00 1.17 2.25 2.80 3.50 2.14 Seite 13 [Stal]
Characteristics of Scheduling Policies FCFS SJF HRRN Selection Function max(w) min(s) Response Time May be high, especially if there is a large variance in process execution times Provides good response time for short processes w + s R = s Provides good response time Overhead Minimum Can be high Can be high Effect on Processes Penalizes short processes; penalizes I/O bound processes Penalizes long processes Starvation No Possible No Good balance w = time spent in systemso far, waiting s = total service time required by the process Seite 14 [Stal]
Priority Scheduling (PS) A priority will be assigned to each process as soon as it starts If a new process arrives, then it will be sorted to the queue appropriate to its priority High priorities are at the top of the queue, lower at the end If several processes have the same priority another policy has to be used (e.g. FCFS) Discriminated jobs may starve (starvation). This can be solved by dynamic priorities E.g. increase priority of waiting processes Seite 15
Preemtive Scheduling In multiuser systems several jobs will be started by different users No jobs should be blocked One of the main methods on such systems is to split calculation time into periods Seite 16
Preemtive Scheduling If a process is ready it is sorted into the queue The dispatcher will be called per timer interrupt A running process will be turned into waiting state and transferred to ready state Then the interrupted process will be put again to the queue The dispatcher will now start the first process from queue CPU Seite 17