89
CS1252-OPERATING SYSTEM UNIT I 1 UNIT 1

ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

Embed Size (px)

Citation preview

Page 1: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 1

UNIT 1

Page 2: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 2

What is an Operating System?

A program that acts as an intermediary between a user of a computer and the computer hardware.

Operating system goals: Execute user programs and make solving user problems

easier. Make the computer system convenient to use.

Use the computer hardware in an efficient manner.

Page 3: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 3

Computer System Components

1. Hardware – provides basic computing resources (CPU, memory, I/O devices).

2. Operating system – controls and coordinates the use of the hardware among the various application programs for the various users.

3. Applications programs – define the ways in which the system resources are used to solve the computing problems of the users (compilers, database systems, video games, business programs).

4. Users (people, machines, other computers).

Page 4: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 4

Abstract View of System Components

Page 5: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 5

Operating System Definitions

Resource allocator – manages and allocates resources.

Control program – controls the execution of user programs and operations of I/O devices .

Kernel – the one program running at all times (all else being application programs).

Page 6: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 6

Mainframe Systems Reduce setup time by batching similar jobs Automatic job sequencing – automatically transfers

control from one job to another. First rudimentary operating system.

Resident monitor initial control in monitor control transfers to job when job completes control transfers pack to monitor

Page 7: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 7

Memory Layout for a Simple Batch System

Page 8: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 8

Multi - programmed Batch SystemsSeveral jobs are kept in main memory at the same time, and the CPU is multiplexed among them.

Page 9: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 9

OS Features Needed for Multiprogramming

I/O routine supplied by the system. Memory management – the system must allocate the

memory to several jobs. CPU scheduling – the system must choose among

several jobs ready to run. Allocation of devices.

Page 10: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 10

Time-Sharing Systems–Interactive Computing

The CPU is multiplexed among several jobs that are kept in memory and on disk (the CPU is allocated to a job only if the job is in memory).

A job swapped in and out of memory to the disk. On-line communication between the user and the

system is provided; when the operating system finishes the execution of one command, it seeks the next “control statement” from the user’s keyboard.

On-line system must be available for users to access data and code.

Page 11: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 11

Desktop Systems

Personal computers – computer system dedicated to a single user.

I/O devices – keyboards, mice, display screens, small printers.

User convenience and responsiveness. Can adopt technology developed for larger operating

system’ often individuals have sole use of computer and do not need advanced CPU utilization of protection features.

May run several different types of operating systems (Windows, MacOS, UNIX, Linux)

Page 12: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 12

Parallel Systems

Multiprocessor systems with more than on CPU in close communication.

Tightly coupled system – processors share memory and a clock; communication usually takes place through the shared memory.

Advantages of parallel system: Increased throughput Economical Increased reliability

graceful degradation fail-soft systems

Page 13: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 13

Parallel Systems (Cont.) Symmetric multiprocessing (SMP)

Each processor runs and identical copy of the operating system.

Many processes can run at once without performance deterioration.

Most modern operating systems support SMP

Asymmetric multiprocessing Each processor is assigned a specific task; master processor

schedules and allocated work to slave processors. More common in extremely large systems

Page 14: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 14

Symmetric Multiprocessing Architecture

Page 15: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 15

Distributed Systems

Distribute the computation among several physical processors.

Loosely coupled system – each processor has its own local memory; processors communicate with one another through various communications lines, such as high-speed buses or telephone lines.

Advantages of distributed systems. Resources Sharing Computation speed up – load sharing Reliability Communications

Page 16: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 16

Distributed Systems (cont)

Requires networking infrastructure. Local area networks (LAN) or Wide area networks

(WAN) May be either client-server or peer-to-peer systems.

Page 17: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 17

General Structure of Client-Server

Page 18: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 18

Clustered Systems

Clustering allows two or more systems to share storage. Provides high reliability. Asymmetric clustering: one server runs the application while

other servers standby. Symmetric clustering: all N hosts are running the application.

Page 19: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 19

Real-Time Systems Often used as a control device in a dedicated

application such as controlling scientific experiments, medical imaging systems, industrial control systems, and some display systems.

Well-defined fixed-time constraints. Real-Time systems may be either hard or soft real-

time.

Page 20: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 20

Real-Time Systems (Cont.)

Hard real-time: Secondary storage limited or absent, data stored in short

term memory, or read-only memory (ROM) Conflicts with time-sharing systems, not supported by

general-purpose operating systems.

Soft real-time Limited utility in industrial control of robotics Useful in applications (multimedia, virtual reality) requiring

advanced operating-system features.

Page 21: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 21

Handheld Systems

Personal Digital Assistants (PDAs) Cellular telephones Issues:

Limited memory Slow processors Small display screens.

Page 22: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 22

Hardware Protection

Dual-Mode Operation I/O Protection Memory Protection CPU Protection

Page 23: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 23

Dual-Mode Operation

Sharing system resources requires operating system to ensure that an incorrect program cannot cause other programs to execute incorrectly.

Provide hardware support to differentiate between at least two modes of operations.1. User mode – execution done on behalf of a user.

2. Monitor mode (also kernel mode or system mode) – execution done on behalf of operating system.

Page 24: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 24

Dual-Mode Operation (Cont.)

Mode bit added to computer hardware to indicate the current mode: monitor (0) or user (1).

When an interrupt or fault occurs hardware switches to monitor mode.

Privileged instructions can be issued only in monitor mode.

monitor user

Interrupt/fault

set user mode

Page 25: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 25

I/O Protection

All I/O instructions are privileged instructions. Must ensure that a user program could never gain control of

the computer in monitor mode (I.e., a user program that, as part of its execution, stores a new address in the interrupt vector).

Page 26: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 26

Use of A System Call to Perform I/O

Page 27: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 27

Memory Protection

Must provide memory protection at least for the interrupt vector and the interrupt service routines.

In order to have memory protection, add two registers that determine the range of legal addresses a program may access: Base register – holds the smallest legal physical memory address. Limit register – contains the size of the range

Memory outside the defined range is protected.

Page 28: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 28

Use of A Base and Limit Register

Page 29: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 29

Hardware Address Protection

Page 30: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 30

Hardware Protection

When executing in monitor mode, the operating system has unrestricted access to both monitor and user’s memory.

The load instructions for the base and limit registers are privileged instructions.

Page 31: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 31

CPU Protection

Timer – interrupts computer after specified period to ensure operating system maintains control. Timer is decremented every clock tick. When timer reaches the value 0, an interrupt occurs.

Timer commonly used to implement time sharing. Time also used to compute the current time. Load-timer is a privileged instruction.

Page 32: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 32

Common System Components

Process Management Main Memory Management File Management I/O System Management Secondary Management Networking Protection System Command-Interpreter System

Page 33: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 33

Contd…

PROCESS MANAGEMENT

A process is a program in execution: (A program is passive, a process active.)

A process has resources (CPU time, files) and attributes that must be managed.

Management of processes includes:

Process Scheduling (priority, time management, . . . ) Creation/termination Block/Unblock (suspension/resumption ) Synchronization Communication Deadlock handling Debugging

Page 34: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 34

Contd…

MAIN MEMORY MANAGEMENT Allocation/de-allocation for processes, files, I/O.

Maintenance of several processes at a time

Keep track of who's using what memory

Movement of process memory to/from secondary storage.

SECONDARY STORAGE MANAGEMENT Disks, tapes, optical, ...

Free space management ( paging/swapping )

Storage allocation ( what data goes where on disk )

Disk scheduling

Page 35: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 35

DEVICE MANAGEMENT Buffer caching system Generic device driver code Drivers for each device - translate read/write requests into disk position commands.

FILE MANAGEMENT

Keep track of what's on secondary storage. file == logical entity, disk == physical entity

Map logical file locations onto physical disk locations. May involve management of a file structure ( directory hierarchy )

· Does file/directory creation/deletion· File manipulation ( rename, move, append )· File backup

Page 36: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 36

PROTECTION

Of files, memory, CPU, etc. Means controlling of access Depends on the attributes of the file and user

COMMUNICATION Communication system between distributed processors. Getting information about files/processes/etc. on a remote machine. Can use either a message passing or a shared memory model.

Page 37: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 37

Operating System Services

Program execution – system capability to load a program into memory and to run it.

I/O operations – since user programs cannot execute I/O operations directly, the operating system must provide some means to perform I/O.

File-system manipulation – program capability to read, write, create, and delete files.

Communications – exchange of information between processes executing either on the same computer or on different systems tied together by a network. Implemented via shared memory or message passing.

Error detection – ensure correct computing by detecting errors in the CPU and memory hardware, in I/O devices, or in user programs.

These are discussed in detail below

Page 38: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 38

Operating System Services One set of operating-system services provides

functions that are helpful to the user: User interface - Almost all operating systems have a user interface (UI)

Varies between Command-Line (CLI), Graphics User Interface (GUI), Batch

Program execution - The system must be able to load a program into memory and to run that program, end execution, either normally or abnormally (indicating error)

I/O operations - A running program may require I/O, which may involve a file or an I/O device.

File-system manipulation - The file system is of particular interest. Obviously, programs need to read and write files and directories, create and delete them, search them, list file Information, permission management.

Page 39: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 39

Operating System Services (Cont.) One set of operating-system services provides

functions that are helpful to the user (Cont): Communications – Processes may exchange information, on the same

computer or between computers over a network Communications may be via shared memory or through message passing

(packets moved by the OS) Error detection – OS needs to be constantly aware of possible errors

May occur in the CPU and memory hardware, in I/O devices, in user program

For each type of error, OS should take the appropriate action to ensure correct and consistent computing

Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system

Page 40: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 40

Operating System Services (Cont.) Another set of OS functions exists for ensuring the efficient operation

of the system itself via resource sharing Resource allocation - When multiple users or multiple jobs running

concurrently, resources must be allocated to each of them Many types of resources - Some (such as CPU cycles,mainmemory, and file

storage) may have special allocation code, others (such as I/O devices) may have general request and release code.

Accounting - To keep track of which users use how much and what kinds of computer resources

Protection and security - The owners of information stored in a multiuser or networked computer system may want to control use of that information, concurrent processes should not interfere with each other Protection involves ensuring that all access to system resources is controlled Security of the system from outsiders requires user authentication, extends to

defending external I/O devices from invalid access attempts If a system is to be protected and secure, precautions must be instituted

throughout it. A chain is only as strong as its weakest link.

Page 41: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 41

User Operating System Interface - CLI

CLI allows direct command entry Sometimes implemented in kernel, sometimes by systems program Sometimes multiple flavors implemented – shells Primarily fetches a command from user and executes it

Sometimes commands built-in, sometimes just names of programs If the latter, adding new features doesn’t require shell modification

Page 42: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 42

User Operating System Interface - GUI

User-friendly desktop metaphor interface Usually mouse, keyboard, and monitor Icons represent files, programs, actions, etc Various mouse buttons over objects in the interface cause various

actions (provide information, options, execute function, open directory (known as a folder)

Invented at Xerox PARC

Many systems now include both CLI and GUI interfaces Microsoft Windows is GUI with CLI “command” shell Apple Mac OS X as “Aqua” GUI interface with UNIX kernel

underneath and shells available Solaris is CLI with optional GUI interfaces (Java Desktop, KDE)

Page 43: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 43

Additional Operating System Functions

Additional functions exist not for helping the user, but rather for ensuring efficient system operations.

• Resource allocation – allocating resources to multiple users or multiple jobs running at the same time.

• Accounting – keep track of and record which users use how much and what kinds of computer resources for account billing or for accumulating usage statistics.

• Protection – ensuring that all access to system resources is controlled.

Page 44: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 44

System Calls System calls provide the interface between a running

program and the operating system. Generally available as assembly-language instructions. Languages defined to replace assembly language for systems

programming allow system calls to be made directly (e.g., C, C++)

Three general methods are used to pass parameters between a running program and the operating system. Pass parameters in registers. Store the parameters in a table in memory, and the table

address is passed as a parameter in a register. Push (store) the parameters onto the stack by the program, and

pop off the stack by operating system.

Page 45: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 45

Example of System Calls

System call sequence to copy the contents of one file to another file

Page 46: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 46

Example of Standard API

Consider the ReadFile() function in the Win32 API—a function for reading from a file

A description of the parameters passed to ReadFile() HANDLE file—the file to be read LPVOID buffer—a buffer where the data will be read into and written from DWORD bytesToRead—the number of bytes to be read into the buffer LPDWORD bytesRead—the number of bytes read during the last read LPOVERLAPPED ovl—indicates if overlapped I/O is being used

Page 47: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 47

System Call Implementation

Typically, a number associated with each system call System-call interface maintains a table indexed according to these

numbers

The system call interface invokes intended system call in OS kernel and returns status of the system call and any return values

The caller need know nothing about how the system call is implemented Just needs to obey API and understand what OS will do as a result call Most details of OS interface hidden from programmer by API

Managed by run-time support library (set of functions built into libraries included with compiler)

Page 48: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 48

API – System Call – OS Relationship

Page 49: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 49

Standard C Library Example C program invoking printf() library call, which calls

write() system call

Page 50: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 50

System Call Parameter Passing

Often, more information is required than simply identity of desired system call Exact type and amount of information vary according to OS and call

Three general methods used to pass parameters to the OS Simplest: pass the parameters in registers

In some cases, may be more parameters than registers Parameters stored in a block, or table, in memory, and address of block

passed as a parameter in a register This approach taken by Linux and Solaris

Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system

Block and stack methods do not limit the number or length of parameters being passed

Page 51: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 51

Passing of Parameters As A Table

Page 52: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 52

Types of System Calls

Process control File management Device management Information maintenance Communications

Page 53: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 53

MS-DOS Execution

At System Start-up Running a Program

Page 54: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 54

UNIX Running Multiple Programs

Page 55: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 55

Communication Models

Msg Passing Shared Memory

Communication may take place using either message passing or shared memory.

Page 56: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 56

System Programs System programs provide a convenient environment for

program development and execution. The can be divided into: File manipulation Status information File modification Programming language support Program loading and execution Communications Application programs

Most users’ view of the operation system is defined by system programs, not the actual system calls.

This is told in detail as below

Page 57: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 57

System Programs

Provide a convenient environment for program development and execution Some of them are simply user interfaces to system calls; others are considerably

more complex File management - Create, delete, copy, rename, print, dump, list, and

generally manipulate files and directories Status information

Some ask the system for info - date, time, amount of available memory, disk space, number of users

Others provide detailed performance, logging, and debugging information Typically, these programs format and print the output to the terminal or other

output devices Some systems implement a registry - used to store and retrieve configuration

information

Page 58: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 58

System Programs (cont’d)

File modification Text editors to create and modify files Special commands to search contents of files or perform transformations of

the text Programming-language support - Compilers, assemblers,

debuggers and interpreters sometimes provided Program loading and execution- Absolute loaders, relocatable

loaders, linkage editors, and overlay-loaders, debugging systems for higher-level and machine language

Communications - Provide the mechanism for creating virtual connections among processes, users, and computer systems Allow users to send messages to one another’s screens, browse web pages,

send electronic-mail messages, log in remotely, transfer files from one machine to another

Page 59: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 59

Process Concept An operating system executes a variety of programs:

Batch system – jobs Time-shared systems – user programs or tasks

Textbook uses the terms job and process almost interchangeably.

Process – a program in execution; process execution must progress in sequential fashion.

A process includes: program counter stack data section

Page 60: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 60

Process State

As a process executes, it changes state new: The process is being created. running: Instructions are being executed. waiting: The process is waiting for some event to occur. ready: The process is waiting to be assigned to a process. terminated: The process has finished execution.

Page 61: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 61

Diagram of Process State

Page 62: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 62

Process Control Block (PCB)Information associated with each process. Process state Program counter CPU registers CPU scheduling information Memory-management information Accounting information I/O status information

Page 63: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 63

Process Control Block (PCB)

Page 64: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 64

CPU Switch From Process to Process

Page 65: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 65

Process 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. Process migration between the various queues.

Page 66: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 66

Ready Queue And Various I/O Device Queues

Page 67: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 67

Representation of Process Scheduling

Page 68: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 68

Schedulers

Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue.

Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU.

Page 69: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 69

Addition of Medium Term Scheduling

Page 70: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 70

Schedulers (Cont.)

Short-term scheduler is invoked very frequently (milliseconds) (must be fast).

Long-term scheduler is invoked very infrequently (seconds, minutes) (may be slow).

The long-term scheduler controls the degree of multiprogramming.

Processes can be described as either: I/O-bound process – spends more time doing I/O than computations,

many short CPU bursts. CPU-bound process – spends more time doing computations; few very

long CPU bursts.

Page 71: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 71

Context Switch

When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process.

Context-switch time is overhead; the system does no useful work while switching.

Time dependent on hardware support.

Page 72: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 72

Process Creation

Parent process create children processes, which, in turn create other processes, forming a tree of processes.

Resource sharing Parent and children share all resources. Children share subset of parent’s resources. Parent and child share no resources.

Execution Parent and children execute concurrently. Parent waits until children terminate.

Page 73: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 73

Process Creation (Cont.)

Address space Child duplicate of parent. Child has a program loaded into it.

UNIX examples fork system call creates new process exec system call used after a fork to replace the process’ memory space

with a new program.

Page 74: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 74

Processes Tree on a UNIX System

Page 75: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 75

Process Termination

Process executes last statement and asks the operating system to decide it (exit). Output data from child to parent (via wait). Process’ resources are deallocated by operating system.

Parent may terminate execution of children processes (abort). Child has exceeded allocated resources. Task assigned to child is no longer required. Parent is exiting.

Operating system does not allow child to continue if its parent terminates. Cascading termination.

Page 76: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 76

Cooperating Processes

Independent process cannot affect or be affected by the execution of another process.

Cooperating process can affect or be affected by the execution of another process

Advantages of process cooperation Information sharing Computation speed-up Modularity Convenience

Page 77: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 77

Producer-Consumer Problem

Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process. unbounded-buffer places no practical limit on the size of the buffer. bounded-buffer assumes that there is a fixed buffer size.

Page 78: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 78

Bounded-Buffer – Shared-Memory Solution

Shared data#define BUFFER_SIZE 10

Typedef struct {

. . .

} item;

item buffer[BUFFER_SIZE];

int in = 0;

int out = 0;

Solution is correct, but can only use BUFFER_SIZE-1 elements

Page 79: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 79

Bounded-Buffer – Producer Process

item nextProduced;

while (1) {

while (((in + 1) % BUFFER_SIZE) == out)

; /* do nothing */

buffer[in] = nextProduced;

in = (in + 1) % BUFFER_SIZE;

}

Page 80: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 80

Bounded-Buffer – Consumer Process

item nextConsumed;

while (1) {while (in == out)

; /* do nothing */nextConsumed = buffer[out];out = (out + 1) % BUFFER_SIZE;

}

Page 81: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 81

Interprocess Communication (IPC)

Mechanism for processes to communicate and to synchronize their actions.

Message system – processes communicate with each other without resorting to shared variables.

IPC facility provides two operations: send(message) – message size fixed or variable receive(message)

If P and Q wish to communicate, they need to: establish a communication link between them exchange messages via send/receive

Implementation of communication link physical (e.g., shared memory, hardware bus) logical (e.g., logical properties)

Page 82: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 82

Implementation Questions

How are links established? Can a link be associated with more than two processes? How many links can there be between every pair of

communicating processes? What is the capacity of a link? Is the size of a message that the link can accommodate fixed

or variable? Is a link unidirectional or bi-directional?

Page 83: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 83

Direct Communication

Processes must name each other explicitly: send (P, message) – send a message to process P receive(Q, message) – receive a message from process Q

Properties of communication link Links are established automatically. A link is associated with exactly one pair of communicating processes. Between each pair there exists exactly one link. The link may be unidirectional, but is usually bi-directional.

Page 84: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 84

Indirect Communication

Messages are directed and received from mailboxes (also referred to as ports). Each mailbox has a unique id. Processes can communicate only if they share a mailbox.

Properties of communication link Link established only if processes share a common mailbox A link may be associated with many processes. Each pair of processes may share several communication

links. Link may be unidirectional or bi-directional.

Page 85: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 85

Indirect Communication Operations

create a new mailbox send and receive messages through mailbox destroy a mailbox

Primitives are defined as:

send(A, message) – send a message to mailbox A

receive(A, message) – receive a message from mailbox A

Page 86: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 86

Indirect Communication

Mailbox sharing P1, P2, and P3 share mailbox A.

P1, sends; P2 and P3 receive. Who gets the message?

Solutions Allow a link to be associated with at most two processes. Allow only one process at a time to execute a receive operation. Allow the system to select arbitrarily the receiver. Sender is notified

who the receiver was.

Page 87: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 87

Synchronization

Message passing may be either blocking or non-blocking. Blocking is considered synchronous Non-blocking is considered asynchronous send and receive primitives may be either blocking or non-

blocking.

Page 88: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 88

Buffering

Queue of messages attached to the link; implemented in one of three ways.1. Zero capacity – 0 messages

Sender must wait for receiver (rendezvous).

2. Bounded capacity – finite length of n messagesSender must wait if link full.

3. Unbounded capacity – infinite length Sender never waits.

Page 89: ANNAUNIVERSITY OPERATING SYSTEM Unit 1.PPT

CS1252-OPERATING SYSTEM UNIT I 89

END