37
Unit 1 Introduction to Operating System Operating System

Unit_1

Embed Size (px)

DESCRIPTION

Operating System

Citation preview

Page 1: Unit_1

Unit 1Introduction to Operating System

Operating System

Page 2: Unit_1

Definition: Operating System

The operating system controls and coordinates the use of the hardware among the various application programs for the various users.

Page 3: Unit_1

Abstract View of System Components

Page 4: Unit_1

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.

Page 5: Unit_1

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 6: Unit_1

Process Concept

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

A process includes: program counter stack data section

Page 7: Unit_1

Process State Transition Diagram

Page 8: Unit_1

Process State Transition Diagram

New: The process is being created. Running: Instructions are being

executed. Waiting: The process is waiting for

some event to occur (such as an I/O completion or reception of a signal). Ready: The process is waiting to be

assigned to a processor.

Page 9: Unit_1

Process Control Block

Page 10: Unit_1

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

Page 11: Unit_1

Context Switch

Page 12: Unit_1

Process Scheduling

The objective of multiprogramming is to have some process running at all times, so as to maximize CPU utilization.

The objective of time-sharing is to switch the CPU among processes so frequently that users can interact with each program while it is running.

Page 13: Unit_1

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

Page 14: Unit_1

Ready Queue And Various I/O Device Queues

Page 15: Unit_1

Queuing Diagram: Representation of Process Scheduling

Page 16: Unit_1

Operations on Process

Process Creation Process Termination

Page 17: Unit_1

Process Creation

Parent process creates 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 18: Unit_1

Process Creation

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

In UNIX, fork system call creates new process execlp system call used after a fork to

replace the process’ memory space with a new program.

Page 19: Unit_1

Fork System Call

System call fork() is used to create processes. It takes no arguments and returns a process ID. If fork() returns a negative value, the creation

of a child process was unsuccessful. fork() returns a zero to the newly created child

process. fork() returns a positive value, the process ID

of the child process, to the parent. a process can use function getpid() to retrieve

the process ID assigned to this process.

Page 20: Unit_1

Unix Example: Child duplicate of parent

Page 21: Unit_1

Unix Example : Child has a program loaded into it

Page 22: Unit_1

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.

Page 23: Unit_1

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

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

Page 24: Unit_1

Producer(P)-Consumer(C)

p C

Page 25: Unit_1

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 26: Unit_1

Producer-Consumer Problem

Producer process

item nextProduced;

while (1) { while (counter == BUFFER_SIZE)

; /* do nothing */ buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; counter++;}

Consumer process item nextConsumed;

while (1) { while (counter == 0)

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

Page 27: Unit_1

Interprocess Communication (IPC)

Mechanism for processes to communicate and to synchronize their actions

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

Page 28: Unit_1

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 29: Unit_1

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 30: Unit_1

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 Areceive(A, message) – receive a message from mailbox A

Page 31: Unit_1

Multithreading

A thread (or lightweight process) is a basic unit of CPU utilization; it consists of: program counter register set stack space

A thread shares with threads of same process: code section data section operating-system resources

Page 32: Unit_1

Benefits

Responsiveness

Resource Sharing

Economy

Utilization of MP Architectures

Page 33: Unit_1

Types of Thread

User-Level Thread

Kernel-Level Thread

Page 34: Unit_1

Multithreading Models

Many-to-One

One-to-One

Many-to-Many

Page 35: Unit_1

Many to One Model

Many user-level threads mapped to single kernel thread.

Page 36: Unit_1

One to One Model

Each user-level thread maps to kernel thread.

Page 37: Unit_1

Many to Many Model

Allows many user level threads to be mapped to many kernel threads.