We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13
Scheduling – Queues – Schedulers
– Context Switching
Prepared by Aswathy K.R ,Asst. Professor,Dept.of CSE, CE
Munnar Scheduling – Queues The objective of multiprogramming is to have some process running at all times, to maximize CPU utilization.
The objective of time sharing is to switch the CPU among
processes so frequently that users can interact with each program while it is running.
Process scheduler selects an available process (possibly from
a set of several available processes) for program execution on the CPU.
For a single-processor system, there will never be more than
one running process. If there are more processes, the rest will have to wait until the CPU is free and can be rescheduled. Scheduling Queues As processes enter the system, they are put into a job queue, which consists of all processes in the system. The processes that are residing in main memory and are ready and waiting to execute are kept on a list called the ready queue. This queue is generally stored as a linked list. A ready-queue header contains pointers to the first and final PCBs in the list. Each PCB includes a pointer field that points to the next PCB in the ready queue. The system also includes other queues. Each device has its own device queue. Scheduling Queues Scheduling Queues
Each rectangular box represents a queue.
Two types of queues are present: the ready queue and a set of device queues. The circles represent the resources that serve the queues, and the arrows indicate the flow of processes in the system. Scheduling Queues A new process is initially put in the ready queue. It waits there until it is selected for execution, or dispatched. Once the process is allocated the CPU and is executing, one of several events could occur: 1. The process could issue an I/O request and then be placed in an I/O queue. 2. The process could create a new child process and wait for the child’s termination. 3. The process could be removed forcibly from the CPU, as a result of an interrupt, and be put back in the ready queue. In the first two cases, the process eventually switches from the waiting state to the ready state and is then put back in the ready queue. A process continues this cycle until it terminates, at which time it is removed from all queues and has its PCB and resources deallocated Schedulers A process migrates among the various scheduling queues throughout its lifetime. The operating system must select, for scheduling purposes, processes from these queues in some fashion. The selection process is carried out by the appropriate scheduler. In a batch system, more processes are submitted than can be executed immediately. These processes are spooled to a mass- storage device (typically a disk), where they are kept for later execution. The long-term scheduler, or job scheduler, selects processes from this pool and loads them into memory for execution. The short-term scheduler, or CPU scheduler, selects from among the processes that are ready to execute and allocates the CPU to one of them. Schedulers The primary distinction between these two schedulers lies in frequency of execution. The short-term scheduler must select a new process for the CPU frequently. The long-term scheduler executes much less frequently; minutes may separate the creation of one new process and the next. Schedulers Processes can be described as either I/O bound or CPU bound. I/O-bound process : Spends more of its time doing I/O than it spends doing computations. CPU-bound process: Generates I/O requests infrequently, using more of its time doing computations. Long-term scheduler select a good process mix of I/O-bound and CPU-bound processes. If all processes are I/O bound, the ready queue will almost always be empty, and the short-term scheduler will have little to do. If all processes are CPU bound, the I/O waiting queue will almost always be empty, devices will go unused, and again the system will be unbalanced. The system with the best performance will thus have a combination of CPU-bound and I/O-bound processes. Schedulers Medium-term scheduler Medium-term scheduler can remove a process from memory (and from active contention for the CPU) and later the process can be reintroduced into memory, and its execution can be continued where it left off. This scheme is called swapping. Swapping is necessary to improve the process mix(CPU bound I/O bound) Context Switch When an interrupt occurs, the system needs to save the current context of the process running on the CPU so that it can restore that context when process resumes. The context is represented in the PCB of the process. It includes the value of the CPU registers, the process state and memory-management information. a context switch is the process of storing and restoring the state (more specifically, the execution context) of a process so that execution can be resumed from the same point at a later time. This enables multiple processes to share a single CPU and is an essential feature of a multitasking operating system. Context Switch When a context switch occurs, the kernel saves the context of the old process in its PCB and loads the saved context of the new process scheduled to run.
Context-switch time is pure overhead, because the system does
no useful work while switching.
Switching speed varies from machine to machine, depending
on the memory speed, the number of registers that must be copied etc. Context Switch Context-switch times are highly dependent on hardware support. For instance, some processors (such as the Sun Ultra SPARC) provide multiple sets of registers. A context switch here simply requires changing the pointer to the current register set.