process concept

27
Silberschatz and Galvin 1999 4.1 Operating System Concepts Processes Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Upload: maha-ibrahim

Post on 16-Jan-2016

213 views

Category:

Documents


0 download

DESCRIPTION

Operating Systems

TRANSCRIPT

Page 1: Process Concept

Silberschatz and Galvin 1999 4.1Operating System Concepts

Processes

• Process Concept

• Process Scheduling

• Operation on Processes

• Cooperating Processes

• Interprocess Communication

Page 2: Process Concept

Silberschatz and Galvin 1999 4.2Operating System Concepts

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;

• A process includes:

– program counter (specifying the next instruction to execute and a set of associated resources)

– Stack (contain temporary data, such as functions, parameters, return addresses and local variables)

– data section (contains global variables)

– Heap (memory that is dynamically allocated during process runtime)

What to call all CPU activities ?

Page 3: Process Concept

Silberschatz and Galvin 1999 4.3Operating System Concepts

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 (such as an I/O completion or reception of signal)

– Ready: The process is waiting to be assigned to a processor.

– Terminated: The process has finished execution.

A program is passive entity, such as file containing a list of instructions stored on disk, often called an executable file.

A program becomes a process when an executable file is loaded into memory .

Page 4: Process Concept

Silberschatz and Galvin 1999 4.4Operating System Concepts

Diagram of Process State

Page 5: Process Concept

Silberschatz and Galvin 1999 4.5Operating System Concepts

Process Control Block (PCB)

Each process is represented in the OS by a PCB that contain information associated with a specific process. e.g.,

• Process state

• Program counter

• CPU registers

• CPU scheduling information

• Memory-management information

• Accounting information

• I/O status information

Page 6: Process Concept

Silberschatz and Galvin 1999 4.6Operating System Concepts

Process Control Block (PCB)

Process state : new, ready, running, waiting etc.

Program counter : indicate the address of the next instruction to be executed for this process

CPU registers : may vary in number and type(accumulators, index register, stack pointers etc.) must be saved when an interrupt occurs, to allow process to be continued correctly afterword

CPU scheduling information : Information about process priority, pointers to scheduling queues etc.

Memory-management information : such values in registers, page tables, segment tables etc

Accounting information : include amount of CPU and real time used, process numbers, time limits etc.

I/O status information : list of I/O devices allocated to the process, etc.

Page 7: Process Concept

Silberschatz and Galvin 1999 4.7Operating System Concepts

CPU Switch From Process to Process

Page 8: Process Concept

Silberschatz and Galvin 1999 4.8Operating System Concepts

Process Scheduling

• The objective of multiprogramming is to have some running process at all times, to maximize CPU utilization. The objective of time sharing is to switch the CPU among processes so frequently that the users can interact with each program while it is running. To meet these objectives, the process scheduler selects an available process(possibly from a set of several available processes) for program execution on the CPU.

• For a single processor system, there will never be more than one running process. If there are more than processes, the rest will have to wait until the CPU is free and can be rescheduled.

Page 9: Process Concept

Silberschatz and Galvin 1999 4.9Operating System Concepts

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 10: Process Concept

Silberschatz and Galvin 1999 4.10Operating System Concepts

Ready Queue And Various I/O Device Queues

Page 11: Process Concept

Silberschatz and Galvin 1999 4.11Operating System Concepts

Representation of Process Scheduling

Page 12: Process Concept

Silberschatz and Galvin 1999 4.12Operating System Concepts

Schedulers

In a batch system, more processes are submitted than can be executed immediately. These processes are spooled to a mass storage device (typically a disk), where they are kept for later execution.

– Long-term scheduler (or job scheduler) – selects which processes should be brought into the ready queue (selects process from the pool and load them in to memory)

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

Page 13: Process Concept

Silberschatz and Galvin 1999 4.13Operating System Concepts

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 14: Process Concept

Silberschatz and Galvin 1999 4.14

Stable degree of multiprogramming

• It is important tha the long term scheduler make a careful selection among I/O bound process and CPU-bound process – process mix.

• If all the processes are I/O bound, the ready queue will almost always be empty, and the short term scheduler will have little to do

• If all processes are CPU-bound, the I/O waiting que will almost always be empty, device will go unused, again the system will be unbalanced.

– Make scheduler absent or minimal : Time sharing systems such as UNIX or MS Windows often have no long term scheudler but simply put every new process in memory for short term scheduler.

– Midium-term scheduler

Operating System Concepts

Schedulers (Cont.)

Page 15: Process Concept

Silberschatz and Galvin 1999 4.15Operating System Concepts

Addition of Medium Term Scheduling

Key idea : Remove processes from memory and thus reduce the degree of Multiprogramming. Later, the process can be reintroduced into memory and Its execution can be contrinued where it left off. This process is called swapping.

Page 16: Process Concept

Silberschatz and Galvin 1999 4.16Operating System Concepts

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 17: Process Concept

Silberschatz and Galvin 1999 4.17Operating System Concepts

Process Creation

• A process may create several new processes, the creating process is call parent process.

• Parent process creates children processes, which, in turn create other processes, forming a tree of processes. Each process is ideentified by a unique integer number – the process identifier (pid)

• 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: Process Concept

Silberschatz and Galvin 1999 4.18Operating System Concepts

Process Creation (Cont.)

• Address space

– The child process is a duplicate of the parent process (it has the same program and data as the parent).

– The child has a new program loaded into it.

Page 19: Process Concept

Silberschatz and Galvin 1999 4.19Operating System Concepts

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 20: Process Concept

Silberschatz and Galvin 1999 4.20Operating System Concepts

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 (concurrent access to shared files)

– Computation speed-up (break into sub-tasks, multi-processing)

– Modularity (dividing functions into seperate process/threads

– Convenience (editing, printing and compiling in paralle)

Page 21: Process Concept

Silberschatz and Galvin 1999 4.21Operating System Concepts

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. The consumer may have to wait for the new items, but the

producer can always produce new items.

– bounded-buffer assumes that there is a fixed buffer size. The consumer must wait if the buffer is empty, and the producer

must wait if the buffer is full.

Page 22: Process Concept

Silberschatz and Galvin 1999 4.22Operating System Concepts

Interprocess Communication (IPC)

• Mechanism for processes to communicate and to synchronize their actions.

• Message system – processes communicate with each other without sharing the same address space.

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

• Logical Implementation of communication link– Direct or indirect communication– Syncronous and Asyncronous communication– Automatic or explicit buffering

Page 23: Process Concept

Silberschatz and Galvin 1999 4.23Operating System Concepts

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 two processes.

– Between each pair there exists exactly one link.

Page 24: Process Concept

Silberschatz and Galvin 1999 4.24Operating System Concepts

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.

• Operations– create a new mailbox– send and receive messages through mailbox– destroy a mailbox

Page 25: Process Concept

Silberschatz and Galvin 1999 4.25Operating System Concepts

Indirect Communication (Continued)

• 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 26: Process Concept

Silberschatz and Galvin 1999 4.26Operating System Concepts

Buffering

• Queue of messages attached to the link; implemented in one of three ways.

1. Zero capacity – 0 messagesSender 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 27: Process Concept

Silberschatz and Galvin 1999 4.27Operating System Concepts

Exception Conditions – Error Recovery

• Process terminates

• Lost messages

• Scrambled Messages