This action might not be possible to undo. Are you sure you want to continue?
CPU Scheduling is the basis of multiprogramming operating systems. By switching the CPU among processes the OS can make the computer more productive. CPU – I/O burst cycle The success of CPU scheduling depends on the following observed property of processes: Process execution consists of a cycle of CPU execution and I/O wait. Processes alternate back and forth between these two states. Process execution begins and ends with a CPU burst. A CPU bound program may have a few long CPU bursts. An I/O bound program would typically have many very short CPU bursts. CPU Scheduler Whenever the CPU becomes idle, the OS must select one of the processes in the ready queue to be executed. The selection process is carried out by the short term scheduler 9or CPU scheduler). The scheduler selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them. Dispatcher The dispatcher is the module that gives control of the CPU to the process selected by the short term scheduler. Diagram of a process state Informally, a process is a program in execution. (a program is a passive entity whereas a process is an active entity) DIAGRAM OF A PROCESS STATE new admitted interrupt exit ready Scheduler dispatch runnin g terminate d
I/O or event completion
I/O or event wait
1. NEW – The process is being created 2. RUNNING – Instructions are being executed 3. WAITING – The process is waiting for some event to occur (I/O completion or reception of a signal) 4. READY – The process is waiting to be assigned to a processor 5. TERMINATED – The process has finished execution
g. the process that requested the CPU first is allocated the CPU first. that process keeps the CPU until it releases the CPU either by terminating or by requesting I/O. and are served in FCFS order. P3. P2. the average waiting time would be 3 milliseconds (calculate!!). Under non preemptive scheduling. . and 27 milliseconds for process P3. we say that the scheduling scheme is non pre-emptive. P3. with the length of the CPU-burst time given in milliseconds: Process P1 P2 P3 Burst time 24 3 3 If the processes arrive in the order P1.Types of scheduling Scheduling can either be preemptive or non preemptive. 24 milliseconds for process P2. (Sum of the periods spent waiting to get into the memory. once the CPU has been allocated for a process. P1. of processes that are completed per unit time • Turnaround time – the interval from the time of submission of a process to the time of completion. but not the time it takes to output that response) Scheduling algorithms FCFS (First Come First Serve) In this non preemptive scheduling scheme. The average waiting time is quite long. E. The implementation of FCFS is easily managed with a FIFO queue. the process keeps the CPU until it releases the CPU or by switching to the waiting state. Scheduling criteria • CPU Utilization – keeping the CPU as busy as possible • Throughput – No. we get the result shown in the following Gantt chart: P1 0 P2 24 27 P3 30 The waiting time is 0 milliseconds for process P1. If the processes arrive in the order P2. Thus. otherwise it is pre-emptive. When scheduling takes place only under circumstances 1 & 4. • Response time – time from the submission of a request until the first response is produced (time it takes to start responding. waiting in the ready queue. consider the following set of processes that arrive at time 0. executing on CPU and doing I/O) • Waiting time – the sum of periods spent waiting in the ready queue. the average waiting time is (0+24+27)/3 = 17 milliseconds. Once the CPU has been allocated to a process.
SJF can either be preemptive or non preemptive. Otherwise. the process itself will release the CPU voluntarily. The CPU scheduler goes around the ready queue allocating the CPU to each process for a time interval of up to 1 time quantum. There is no way to know the length of the next CPU burst and hence SJF is not implemented at the level of short-term CPU scheduling. but preemption is added to switch between processes. of open files. A small unit of time called time quantum or time slice is defined. . A ready queue is treated as a circular queue. the type and amount of funds being paid for computer use. E. such as the importance of the process. This can be solved by a technique called aging wherein we gradually increase the priority of a long waiting process. Performance depends heavily on the time quantum. memory requirements. Priority can be defined either internally or externally. A non preemptive priority scheduling algorithm will simply put the new process at the head of the ready queue. and appears (in theory) to the users as though each of n processes has its own processor running at 1/n the speed of the real processor. ratio of average I/O burst time to average CPU burst time etc. the RR approach is called processor sharing. It is similar to FCFS. Average waiting time under the RR policy is quite long. time limits. FCFS is used to break the tie if two processes have the same length. New processes are added to the tail of the ready queue.g. and the CPU is allocated to the process with the highest priority. Preemptive is sometimes called Shortest Remaining Time First (SRTF) scheduling. the timer will go off and will cause an interrupt to the operating system. Internally defined priorities use some measurable quantities to compute the priority of a process. If the time quantum is very small. the RR policy is same as the FCFS policy. A preemptive priority scheduling algorithm will preempt the CPU if the priority of the newly arrived process is higher than the priority of the currently running process. if the time quantum is longer than 1 time quantum. the CPU is assigned to the process that has the smallest next CPU burst. external priorities are set by criteria that are external to the OS. At one extreme if the time quantum is very large (infinite). A context switch will be executed and the process will be put at the tail of the ready queue. no. Priority scheduling can be preemptive or non preemptive. If the process has a CPU burst of less than 1 time quantum. Priority Scheduling A priority is associated with each process. One way is to compute an approximation of the length of the next CPU burst and pick the process with the shortest predicted CPU burst. RR (Round Robin) Scheduling This algorithm is specially designed for timesharing systems.SJF (Shortest Job First) In this scheme. A major problem with priority scheduling algorithms is indefinite blocking or starvation. SJF is frequently used in long term scheduling. the department sponsoring work and other often political factors.
Similarly a process that waits too long in a lower priority queue may be moved to a higher priority queue. there must be scheduling between the queues which is mostly implemented as fixed priority preemptive scheduling Highest priority System processes Interactive processes Interactive editing processes Batch processes Student processes Lowest priority Multilevel feedback queue scheduling Allows a process to move between queues. it will be moved to a lower priority queue. The processes are permanently assigned to one queue based on some property of the process. If a process uses too much CPU time.Multilevel queue scheduling This algorithm partitions the ready queue nto several separate queues. =============================================================== . Each queue has its own scheduling algorithm. This scheme leaves I/O bound and interactive processes in the higher priority queues. In addition.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue listening from where you left off, or restart the preview.