Preemptive And Non Preemptive Algorithms-Operating Systems-Lecture Notes, Study notes of Operating Systems

Operating Systems is necessary course in Computer Science. Its about threading, process scheduling, deadlocks, memory management etc. This lecture includes: Preemptive, Algorithms, Operating, System, Time, Unix, Size, Linux, Schedule, Process, Bursts, Execution

Typology: Study notes

2011/2012

Uploaded on 08/06/2012

sarang
sarang ๐Ÿ‡ฎ๐Ÿ‡ณ

4.5

(47)

86 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
77
Operating Systems [CS-604] Lecture No.14
Operating Systems
Lecture No. 14
Reading Material
๎˜‚๎˜ƒChapter 6 of the textbook
๎˜‚๎˜ƒLecture 14 on Virtual TV
Summary
๎˜‚๎˜ƒBasic concepts
๎˜‚๎˜ƒScheduling criteria
๎˜‚๎˜ƒPreemptive and non-preemptive algorithms
๎˜‚๎˜ƒFirst-Come-First-Serve scheduling algorithm
Basic Concepts
The objective of multiprogramming is to have some process running at all times, in order
to maximize CPU utilization. In a uniprocessor system, only one process may run at a
time; any other processes much wait until the CPU is free and can be rescheduled.
In multiprogramming, a process is executed until it must wait, typically for the
completion of some I/O request. In a simple computer system, the CPU would then sit
idle; all this waiting time is wasted. Multiprogramming entails productive usage of this
time. When one process has to wait, the OS takes the CPU away from that process and
gives the CPU to another process. Almost all computer resources are scheduled before
use.
Life of a Process
As shown in Figure 14.1, process execution consists of a cycle of CPU execution and I/O
wait. Processes alternates between these two states. Process execution begins with a CPU
burst. An I/O burst follows that, and so on. Eventually, the last CPU burst will end with
a system request to terminate execution, rather than with another I/O burst.
An I/O bound program would typically have many very short CPU bursts. A CPU-
bound program might have a few very long CPU bursts. This distribution can help us
select an appropriate CPU-scheduling algorithm. Figure 14.2 shows results on an
empirical study regarding the CPU bursts of processes. The study shows that most of the
processes have short CPU bursts of 2-3 milliseconds.
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Preemptive And Non Preemptive Algorithms-Operating Systems-Lecture Notes and more Study notes Operating Systems in PDF only on Docsity!

Operating Systems [CS-604] Lecture No.

Operating Systems

Lecture No. 14

Reading Material

Chapter 6 of the textbook Lecture 14 on Virtual TV

Summary

Basic concepts Scheduling criteria Preemptive and non-preemptive algorithms First-Come-First-Serve scheduling algorithm

Basic Concepts

The objective of multiprogramming is to have some process running at all times, in order to maximize CPU utilization. In a uniprocessor system, only one process may run at a time; any other processes much wait until the CPU is free and can be rescheduled. In multiprogramming, a process is executed until it must wait, typically for the completion of some I/O request. In a simple computer system, the CPU would then sit idle; all this waiting time is wasted. Multiprogramming entails productive usage of this time. When one process has to wait, the OS takes the CPU away from that process and gives the CPU to another process. Almost all computer resources are scheduled before use.

Life of a Process

As shown in Figure 14.1, process execution consists of a cycle of CPU execution and I/O wait. Processes alternates between these two states. Process execution begins with a CPU burst. An I/O burst follows that, and so on. Eventually, the last CPU burst will end with a system request to terminate execution, rather than with another I/O burst. An I/O bound program would typically have many very short CPU bursts. A CPU- bound program might have a few very long CPU bursts. This distribution can help us select an appropriate CPU-scheduling algorithm. Figure 14.2 shows results on an empirical study regarding the CPU bursts of processes. The study shows that most of the processes have short CPU bursts of 2-3 milliseconds.

Figure 14.1 Alternating Sequence of CPU and I/O Bursts

Figure 14.2 Histogram of CPU-burst Times

Scheduling Criteria

The scheduling criteria include:  CPU utilization : We want to keep CPU as busy as possible. In a real system it should range from 40 percent (for a lightly loaded system) to 90 percent (for a heavily used system)  Throughput: If CPU is busy executing processes then work is being done. One measure of work is the number of processes completed per time, called, throughput. We want to maximize the throughput.  Turnaround time: The interval from the time of submission 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. We want to minimize the turnaround time.  Waiting time: Waiting time is the time spent waiting in the ready queue. We want to minimize the waiting time to increase CPU efficiency.  Response time: It is the time from the submission of a request until the first response is produced. Thus response time is the amount of time it takes to start responding but not the time it takes to output that response. Response time should be minimized.

Scheduling Algorithms

We will now discuss some of the commonly used short-term scheduling algorithms. Some of these algorithms are suited well for batch systems and others for time-sharing systems. Here are the algorithms we will discuss: First-Come-First-Served (FCFS) Scheduling Shorted Job First (SJF) Scheduling Shortest Remaining Time First (SRTF) Scheduling Priority Scheduling Round-Robin Scheduling Multilevel Queues Scheduling Multilevel Feedback Queues Scheduling UNIX System V Scheduling

First-Come, First-Served (FCFS) Scheduling The process that requests the CPU first (i.e., enters the ready queue first) is allocated the CPU first. The implementation of an FCFS policy is managed with a FIFO queue. When a process enters the ready queue, its PCB is linked onto the tail of the queue. When CPU is free, it is allocated to the process at the head of the queue. The running process is removed from the queue. The average waiting time under FCFS policy is not minimal and may vary substantially if the process CPU-burst times vary greatly. FCFS is a non- preemptive scheduling algorithm. We use the following system state to demonstrate the working of this algorithm. For simplicity, we assume that processes are in the ready queue at time 0.

Process Burst Time P1 24 P2 3 P3 3 Suppose that processes arrive into the system in the order: P1, P2, P3. Processes are served in the order: P1, P2, P3.The Gantt chart for the schedule is shown in Figure 14.3.

Figure 14.3 Gantt chart showing execution of processes in the order P1, P2, P

Here are the waiting times for the three processes and the average waiting time per process. Waiting times P1 = 0; P2 = 24; P3 = 27 Average waiting time: (0+24+27)/3 = 17

Suppose that processes arrive in the order: P2, P3, P1. The Gantt chart for the schedule is shown in Figure 14.4:

Figure 14.4 Gantt chart showing execution of processes in the order P2, P3, P

Here are the waiting times for the three processes and the average waiting time per process. Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3

When FCFS scheduling algorithm is used, the convoy effect occurs when short processes wait behind a long process to use the CPU and enter the ready queue in a convoy after completing their I/O. This results in lower CPU and device utilization than might be possible if shorter processes were allowed to go first. In the next lecture, we will discuss more scheduling algorithms.

P 1 P 2 P 3

P 2 P 3 P 1