Scheduling Operating Systems Nyan Dawood 2018 2019 Scheduling

  • Slides: 16
Download presentation
Scheduling (Operating Systems) Nyan Dawood 2018 -2019

Scheduling (Operating Systems) Nyan Dawood 2018 -2019

Scheduling Queues • As processes enter the system, they are put into a job

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. Each PCB includes a pointer field that points to the next PCB in the ready queue.

Scheduling Queues (cont. ) The system also includes other queues. When a • process

Scheduling Queues (cont. ) The system also includes other queues. When a • process is allocated the CPU, it executes for a while and eventually quits, is interrupted, or waits for the occurrence of a particular event, such as the completion of an I/O request. Suppose the process makes an I/O request to a shared • device. Since there are many processes in the system, the device may be busy with the I/O request of some other process. The list of processes waiting for a particular I/O device • is called a device queue. Each device has its own device queue

Scheduling Queues • Job queue – set of all processes in the system •

Scheduling Queues • Job queue – set of all processes in the system • Ready queue – set of all processes residing in main memory, ready and waiting to execute • Device queues – set of processes waiting for an I/O device Processes migrate among the various queues

Schedulers • A process migrates among the various scheduling queues throughout its lifetime. The

Schedulers • A process migrates among the various scheduling queues throughout its lifetime. The operating system must select, processes from these queues in some fashion. The selection process is carried out by the appropriate scheduler. • Often, 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.

Schedulers (cont. ) • The long-term scheduler, or job scheduler, selects processes from this

Schedulers (cont. ) • The long-term scheduler, or job scheduler, selects processes from this pool and loads them into memory for execution. The shortterm scheduler, or CPU scheduler, selects from among the processes that are ready to execute and allocates the CPU to one of them. • The primary difference between these two schedulers lies in frequency of execution.

short-term scheduler • The short-term scheduler must select a new process for the CPU

short-term scheduler • The short-term scheduler must select a new process for the CPU frequently. A process may execute for only a few milliseconds before waiting for an I/O request. • Often, the short-term scheduler executes at least once every 100 milliseconds. Because of the short time between executions, the shortterm scheduler must be fast.

long-term scheduler The long-term scheduler executes much less frequently; minutes may separate the creation

long-term scheduler The long-term scheduler executes much less frequently; minutes may separate the creation of one new process and the next. The long-term scheduler controls the degree of multiprogramming (the number of processes in memory). Note: On some systems, the long-term scheduler may be absent or minimal. For example, UNIX and Microsoft Windows systems often have no long-term scheduler but simply put every new process in memory for the short-term scheduler.

long-term scheduler (cont. ) • It is important that the long-term scheduler make a

long-term scheduler (cont. ) • It is important that the long-term scheduler make a careful selection. In general, most processes can be described as either I/O bound or CPU bound. • An I/O-bound process is one that spends more of its time doing I/O than it spends doing computations. • A CPU-bound process, in contrast, generates I/O requests infrequently, using more of its time doing computations.

Process mix • It is important that the long-term scheduler select a good process

Process mix • It is important that the long-term scheduler select a good process mix of I/O-bound and CPU-bound • 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.

CPU-I/O Burst Cycle • Process execution begins with a CPU burst. That is followed

CPU-I/O Burst Cycle • Process execution begins with a CPU burst. That is followed by an I/O burst, which is followed by another CPU burst, then another I/O burst, and so on. • Eventually, the final CPU burst ends with a system request to terminate execution. • An I/O-bound program typically has many short CPU bursts. A CPU-bound program might have a few long CPU bursts.

CPU Scheduler • CPU scheduling decisions may take place when a process: 1. 2.

CPU Scheduler • CPU scheduling decisions may take place when a process: 1. 2. 3. 4. Switches from running to waiting state Switches from running to ready state Switches from waiting to ready Terminates • Scheduling under 1 and 4 is nonpreemptive • other scheduling is preemptive

CPU Scheduler • Under nonpreemptive scheduling, once the CPU has been allocated to a

CPU Scheduler • Under nonpreemptive scheduling, once the CPU has been allocated to a process, the process keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state. • Windows 95 introduced preemptive scheduling, and all subsequent versions of Windows operating systems have used preemptive scheduling.

Scheduling Criteria • CPU utilization – keep the CPU as busy as possible •

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 • Waiting time – amount of time a process has been waiting in the ready queue • Response time – amount of time it takes from when a request was submitted until the first response is produced.

Optimization Criteria • • • Max CPU utilization Max throughput Min turnaround time Min

Optimization Criteria • • • Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time

Scheduling Algorithms • • • First-Come, First-Served Scheduling Shortest-Job-First Scheduling Priority Scheduling Round-Robin Scheduling

Scheduling Algorithms • • • First-Come, First-Served Scheduling Shortest-Job-First Scheduling Priority Scheduling Round-Robin Scheduling Multilevel Queue Scheduling Multilevel Feedback-Queue Scheduling