0% found this document useful (0 votes)
29 views13 pages

4.1 Cpu Scheduling

process and cpu sceduling in OS

Uploaded by

hrajaa16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views13 pages

4.1 Cpu Scheduling

process and cpu sceduling in OS

Uploaded by

hrajaa16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Operating System

By
Mr. Parag R. Sali
Lecturer
Department of Computer Technology
SNJB’s Shri. Hiralal Hastimal ( Jain Brothers)
Polytechnic, Chandwad
Program Name: Computer Engineering Group
Program Code : CO/CM/IF/CW
Semester : Fifth
Course Title : Operating System
Course Code : 22516

4. CPU Scheduling & Algorithms


Basic Concepts
In a single-processor system, only one process can run at a time. Others must
wait until the CPU is free and can be rescheduled. The objective of
multiprogramming is to have some process running at all times, 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 multiprogramming, 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.
CPU–I/O Burst Cycle

The success of CPU scheduling depends on an observed property of


processes: process execution consists of a cycle of CPU execution and
I/O wait. Processes alternate between these two states. 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 (Figure 1)
Figure 1 Alternating sequence of CPU and I/O bursts.
CPU Scheduler
Whenever the CPU becomes idle, the operating system must select one of
the processes in the ready queue to be executed. The selection process is
carried out by the short-term scheduler, or CPU scheduler. The scheduler
selects a process from the processes in memory that are ready to execute
and allocates the CPU to that process.
CPU scheduling decisions may take place when a process:
1. Switches from running to waiting state
2. Switches from running to ready state
3. Switches from waiting to ready
4. Terminates

Scheduling under 1 and 4 is nonpreemptive


All other scheduling is preemptive
Preemptive Scheduling
CPU-scheduling decisions may take place under the following four
circumstances:
1. When a process switches from the running state to the waiting state (for
example, as the result of an I/O request or an invocation of wait() for the
termination of a child process)
2. When a process switches from the running state to the ready state (for
example, when an interrupt occurs)
3. When a process switches from the waiting state to the ready state (for
example, at completion of I/O)
4. When a process terminates
Dispatcher
Another component involved in the CPU-scheduling function is the dispatcher.
The dispatcher is the module that gives control of the CPU to the process
selected by the short-term scheduler. This function involves the following:
• Switching context
• Switching to user mode
• Jumping to the proper location in the user program to restart that program

The dispatcher should be as fast as possible, since it is invoked during every


process switch. The time it takes for the dispatcher to stop one process and
start another running is known as the dispatch latency.
Scheduling Criteria:
1. CPU utilization.
2. Throughput.
3. Turnaround time.
4. Waiting time.
5. Response time
Many criteria have been suggested for comparing CPU-scheduling
algorithms. Which characteristics are used for comparison can make a
substantial difference in which algorithm is judged to be best. The criteria
include the following:
• CPU utilization. We want to keep the CPU as busy as possible.
Conceptually, CPU utilization can range from 0 to 100 percent. In a real
system, it should range from 40 percent (for a lightly loaded system) to 90
percent (for a heavily loaded system).
• Throughput. If the CPU is busy executing processes, then work is being
done. One measure of work is the number of processes that are
completed per time unit, called throughput. For long processes, this rate
may be one process per hour; for short transactions, it may be ten
processes per second.
• Turnaround time. From the point of view of a particular process, the important
criterion is how long it takes to execute that process. The interval from the time of
submission of a process to the time of completion is the turnaround time.
Turnaround time is the sum of the periods spent waiting to get into memory,
waiting in the ready queue, executing on the CPU, and doing I/O.

• Waiting time. The CPU-scheduling algorithm does not affect the amount of time
during which a process executes or does I/O. It affects only the amount of time
that a process spends waiting in the ready queue. Waiting time is the sum of the
periods spent waiting in the ready queue.
• Response time. In an interactive system, turnaround time may not be the
best criterion. Often, a process can produce some output fairly early and can
continue computing new results while previous results are being output to
the user. Thus, another measure is the time from the submission of a request
until the first response is produced. This measure, called response time, is the
time it takes to start responding, not the time it takes to output the response.
The turnaround time is generally limited by the speed of the output device.

You might also like