You are on page 1of 46

COMPUTER ENGINEERING

CHAPTER 6 OPERATING SYSTEM &SCHEDULING

Outcomes
2

After completing this chapter student should be able to:


Describe basic role of an operating system Identify the major operating system software subsystem

managers and their functions Identify type of operating system Discuss the goals of process scheduling policies Determine time line for up to six different process scheduling algorithms

What is an Operating System?


3

Operating System: Part of the computing system that manages all of the hardware and software Controls every file, every device, every section of main memory, and every nanosecond of processing time Controls who can use the system and how Computer system consists of: Software (programs) Hardware (the physical machine and its electronic components)

Objectives
4

Convenience

Making the computer easier to use Allowing better use of computer resources

Efficiency

Functions
5

Process Scheduling

OS determines which process should run at any given time Introducing a virtual memory Benefit
A

Memory Management

process can run in main memory without all instructions and data for that program present at main memory at one time Total memory space available to a program may exceed the actual main memory on the system

The OS masks the details of the hardware from the programmer and provides the programmer with a convenient interface for using the system

Layers and Views of a Computer System

Operating System Services


7

Program creation Program execution Access to I/O devices Controlled access to files System access Error detection and response Accounting

8 Illustrate the main resources that are managed by the OS. A portion of OS is in main memory. The remainder contains user program and data The allocation of this resource ( main memory) is controlled by the OS The OS decide when I/O device can be used by a program in execution, and control access to and use of files OS determine how much processor time is devoted to the execution of program

O/S as a Resource Manager

Essential managers of an operating system:


Memory Manager Processor Manager Device Manager File Manager

At top; User Command Interface users issue command to the OS User Command Interface is unique to each operating system

Figure 1.1: Model of a non-networked operating system

Operating System Software (continued)


10

Each subsystem manager must perform the

following tasks:

Monitor its resources continuously Enforce the policies that determine who gets what, when, and how much Allocate the resource when its appropriate Deallocate the resource when appropriate

11 Operating System Software (continued)

Figure 1.2: Subsystems managers at the base of a pyramid

Operating System Software (continued)


12

Memory Manager: In charge of main memory

(RAM) Responsibilities include:


Preserves the space in main memory occupied by the operating system Checks the validity of each request for memory space Sets up a table to keep track of who is using which section of memory in a multiuser environment Deallocates memory when the time comes to reclaim the memory

Operating System Software (continued)


13

Processor Manager decides how to allocate the

central processing unit (CPU) Keep track of the status of each process Processor Manager has two levels of responsibility:

To handle jobs as they enter the system


Handled

by Job Scheduler by Process Scheduler

To manage each process within those jobs


Handled

Operating System Software (continued)


14

Device Manager monitors every device, channel,

and control unit Responsibilities include:

Chooses the most efficient way to allocate all of the systems devices, printers, terminals, disk drives, based on a scheduling policy Makes the allocation, starts its operation Deallocates the device

Operating System Software (continued)


15

File Manager keeps track of every file in the system

including data files, assemblers, compilers, and application programs Responsibilities include:

Enforces restrictions on who has access to which files by using predetermined access Controls what users are allowed to do with files once they access them Allocates the resource by opening the file and deallocates it by closing the file

Operating System Software (continued)


16

Operating systems with networking capability have a

fifth essential manager called the Network Manager Network Manager provides a convenient way for users to share resources while controlling users access to them. The resources include:

Hardware (such as CPUs, memory areas, printers, tape drives, modems, and disk drives) Software (such as compilers, application programs, and data files)

Operating System 17 Software (continued)

Figure 1.3: Model of a networked operating system

Machine Hardware
18

Essential hardware components include:


Memory chips Input/output devices Storage devices Central processing unit (CPU)

19 Machine Hardware (continued)

Figure 1.4: Computer system hardware configuration

Machine Hardware (continued)


20

Table 1.1: Different platforms and operating systems

Types of Operating System


Interactive - Allow users to interact directly with the
21

computer ( through keyboard/ display) to request the execution of the job Batch user program is batched together with programs from other users and submitted by a computer operator. After the program is completed. Results are printed out for the user Single program (Uni-programming)- works only one program at a time Multi-programming (Multi-tasking) made to keep the processor as busy as possible; ( when 1 program waiting for I/O, another can use the CPU )

Single Program
22

Multi-Programming with Two Programs


23

Multi-Programming with Three Programs


24

Scheduling
25

Key to multi-programming

Determines which jobs will get the CPU, when, and for how long Decides when processing should be interrupted Determines which queues the job should be moved to during its execution Recognizes when a job has concluded and should be terminated

Process Scheduling Policies


26

Operating system must resolve three limitations of a

system before scheduling all jobs in a multiprogramming environment:

Finite number of resources (e.g., disk drives, printers, and tape drives) Some resources cant be shared once theyre allocated (e.g., printers) Some resources require operator intervention (e.g., tape drives)

Process Scheduling Policies (continued)


27

A good process scheduling policy should Maximize throughput by running as many jobs as

possible in a given amount of time

Minimize response time by quickly turning around interactive requests Minimize turnaround time by moving entire jobs in and out of system quickly Minimize waiting time by moving jobs out of READY queue as quickly as possible

Process Scheduling Policies (continued)


28

(continued):

Maximize CPU efficiency by keeping CPU busy 100 percent of time Ensure fairness for all jobs by giving every one an equal amount of CPU and I/O time

Process Scheduling Policies (continued)


29

Need for Interrupts: When a job claims CPU for a

very long time before issuing an I/O request


Builds up READY queue & empties I/O queues Creates an unacceptable imbalance in the system

Process Scheduler uses interrupts when a

predetermined slice of time has expired


Suspends all activity on the currently running job Reschedules it into the READY queue

Process Scheduling Policies (continued)


30

Types of Scheduling Policies:

Preemptive scheduling policy:


Interrupts

processing of a job and transfers the CPU to another job without external interrupts

Nonpreemptive scheduling policy:


Functions

Process Scheduling Algorithms


31

Types of Process Scheduling Algorithms:


First Come, First Served (FCFS) Shortest Job Next (SJN) Priority Scheduling Shortest Remaining Time (SRT) Round Robin Multiple Level Queues

First-Come, First-Served
32

Nonpreemptive Handles jobs according to their arrival time: the

earlier they arrive, the sooner theyre served Simple algorithm to implement: uses a FIFO queue Good for batch systems; unacceptable for interactive systems Turnaround time is unpredictable

First-Come, First-Served (continued)


33

Jobs arrival sequence: A, B, C Job A has a CPU cycle of 15 milliseconds Job B has a CPU cycle of 2 milliseconds Job C has a CPU cycle of 1 millisecond

Average turnaround time: 16.67 s Figure 4.5: Timeline for job sequence A, B, C using the FCFS algorithm

First-Come, First-Served (continued)


34

Jobs arrival sequence: C, B, A Job A has a CPU cycle of 15 milliseconds Job B has a CPU cycle of 2 milliseconds Job C has a CPU cycle of 1 millisecond

Average turnaround time: 7.3 s Figure 4.6: Timeline for job sequence C, B, A using the FCFS algorithm

Shortest Job Next (SJN) / shortest job first


35

Nonpreemptive Handles jobs based on length of their CPU cycle time Easiest to implement in batch environments Doesnt work in interactive systems Optimal only when all jobs are available at same time

and the CPU estimates are available and accurate

SJN / SJF (continued)


36

Four batch jobs A, B, C, D, all in the READY queue Job: A B C D CPU cycle: 5 2 6 4

Average turnaround time: 9 s Figure 4.7: Timeline for job sequence B, D, A, C using the SJN algorithm

Shortest Remaining Time


37

Preemptive version of the SJN algorithm Processor allocated to job closest to completion Current job can be preempted if newer job in READY queue has shorter time to completion Cannot be implemented in interactive system Requires advance knowledge of the CPU time required to finish each job SRT involves more overhead than SJN OS monitors CPU time for all jobs in READY queue and performs context switching

Shortest Remaining Time (continued)


38

Arrival time: Job: CPU cycle:

0 1 2 3 A B C D 6 3 1 4

Job: A B C D Turnaround: 14 4 1 6 Average Turnaround: 6.25s

Figure 4.8: Timeline for job sequence A, B, C, D using the preemptive SRT algorithm

Shortest Remaining Time (continued)


39

Arrival time: Job: CPU cycle:

0 1 2 3 A B C D 6 3 1 4

Job: A B C D Turnaround: 6 9 5 11 Average Turnaround: 7.75s

Figure 4.9: Timeline for job sequence A, B, C, D using the nonpreemptive SJN algorithm

Priority Scheduling
40

Nonpreemptive Gives preferential treatment to important jobs


Programs with highest priority are processed first Not interrupted until CPU cycles are completed or a natural wait occurs

FCFS policy is used if two or more jobs with equal

priority in READY queue System administrator or Processor Manager use different methods of assigning priorities

Round Robin
41

Preemptive Used extensively in interactive systems Based on a predetermined slice of time (time

quantum) thats given to each job Size of time quantum crucial to system performance

Usually varies from 100 ms to 1-2 s

Ensures CPU is equally shared among all active

processes and is not monopolized by any one job

Round Robin (continued)


42

Arrival time: 0 1 2 3 Job: A B C D CPU cycle: 8 4 9 5 Time slice: 4ms

Job: A B C D Turnaround: 20 7 24 22 Average Turnaround: 18.25 s

Figure 4.10: Timeline for job sequence A, B, C, D using the preemptive round robin algorithm

Round Robin (continued)


43

If Jobs CPU cycle > time quantum

Job is preempted and put at the end of the READY queue and its information is saved in its PCB

If Jobs CPU cycle < time quantum

If job is finished, all resources allocated to it are released & completed job is returned to user If interrupted by I/O request, then info is saved in PCB & it is linked at end of the appropriate I/O queue Once I/O request is satisfied, job returns to end of READY queue to await allocation of CPU

Round Robin (continued)


44

CPU cycle of job A: 8 ms

Figure 4.11: Context switches for job A with three different time quantums. In (a) the job finishes before the time quantum expires. In (b) and (c), the time quantum expires first, interrupting the job.

Round Robin (continued)


45

Efficiency depends on the size of time quantum in

relation to the average CPU cycle If the quantum is too large - larger than most CPU cycles

Algorithm reduces to the FCFS scheme Amount of context switching slows down the execution of the jobs Amount of overhead is dramatically increased

If the quantum is too small

Round Robin (continued)


46

General rules of thumb for selecting the proper time

quantum:

Should be long enough to allow 80% of CPU cycles to run to completion Should be at least 100 times longer than the time required to perform one context switch

These rules are flexible and depend on the system

You might also like