Académique Documents
Professionnel Documents
Culture Documents
Introduction
Scheduling is the method by which threads, processes or data flows are given access to system resources (e.g. processor time, communications bandwidth). This is usually done to load balance a system effectively or achieve a target quality of service. The need for a scheduling algorithm arises from the requirement for most modern systems to perform multitasking (execute more than one process at a time) and multiplexing (transmit multiple flows simultaneously). In a single processor system, only one process can run at a time; any others must wait until the CPU is free and can be re-scheduled. The objective of multi-programming is to have some process running at all time, to maximize CPU utilization. The idea is relatively simple. A process is executed until it must wait, typically for the completion of some I/O request. In a simple computer system, the CPU then just sits idle. All this waiting time is wasted; no useful work is accomplished. With multi-programming, we try to use this time productively. Several processes are kept in memory at one time. When one process has to wait, the operating system takes the CPU away from that process and gives the CPU to another process. This pattern continues. Every time one process has to wait, another process can take over use of the CPU. Scheduling of this kind is a fundamental operating system function. Almost all computer resources are schedule before use. The CPU is one of the primary computer resources. Thus, its scheduling is central to operating system design.
Efficiency Scheduler should keep the system (or in particular CPU) busy cent percent of the time when possible. If the CPU and all the Input/Output devices can be kept running all the time, more work gets done per second than if some components are idle. Response Time A scheduler should minimize the response time for interactive user. Turnaround A scheduler should minimize the time batch users must wait for an output. Throughput A scheduler should maximize the number of jobs processed per unit time.
Preemptive Scheduling A scheduling discipline is preemptive if, once a process has been given the CPU can taken away. The strategy of allowing processes that are logically runable to be temporarily suspended is called Preemptive Scheduling and it is contrast to the "run to completion" method.
Scheduling Techniques
First-come First-serve Scheduling Round Robin Scheduling Priority Scheduling Shortest Job First Scheduling
Disadvantages: Average waiting time is highly variable. Shorter jobs may wait behind longer ones. May lead to poor overlap between I/O and CPU processing. CPU bound processes will make I/O bound processes to wait and hence those devices remain idle.
Disadvantages: A continuous stream of short jobs will starve the longer jobs. Finding out the shortest runnable process is problematic.
Priority Scheduling
A priority is associated with each process, and the CPU is allocated to the process with the highest priority. Equal priority processes are scheduled in FCFS order. An SJF algorithm is simply a priority algorithm where the priority is the inverse of the (predicted) next CPU burst. The larger the CPU burst, the lower the priority, and vice-versa. Priorities can be defined either internally or externally. Internally defined priorities use some measurable quantity to compute the priority of the process. For example, time limits, memory requirements, the number of open files, and the ratio of average I/O burst to average CPU burst have been used in computing priorities. External priorities are set by criteria outside the operating system such as the importance of the process. It can be either preemptive or nonpreemptive. Example - the processes A, B, C, D, E are assigned priority numbers 2, 3,5,1,4. The execution order of the processes will be: C, A, B, E, D.
Example -The time slot could be 100 milliseconds. If job1 takes a total time of 250ms to complete, the round-robin scheduler will suspend the job after 100ms and give other jobs their time on the CPU. Once the other jobs have had their equal share (100ms each), job1 will get another allocation of CPU time and the cycle will repeat. This process continues until the job finishes and needs no more time on the CPU. Job1 = Total time to complete 250ms (quantum 100ms). First allocation = 100ms. Second allocation = 100ms. Third allocation = 100ms but job1 self-terminates after 50ms. Total CPU time of job1 = 250ms.