Processes: Process Concept Process Scheduling Operation On Processes Cooperating Processes Interprocess Communication

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 27

Processes

Process Concept
Process Scheduling
Operation on Processes
Cooperating Processes
Interprocess Communication

Operating System Concepts

4.1

Silberschatz and Galvin 1999

Process Concept
What to call all CPU activities ?

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)

Operating System Concepts

4.2

Silberschatz and Galvin 1999

Process State
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 .

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.

Operating System Concepts

4.3

Silberschatz and Galvin 1999

Diagram of Process State

Operating System Concepts

4.4

Silberschatz and Galvin 1999

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

Operating System Concepts

4.5

Silberschatz and Galvin 1999

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.

Operating System Concepts

4.6

Silberschatz and Galvin 1999

CPU Switch From Process to Process

Operating System Concepts

4.7

Silberschatz and Galvin 1999

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.

Operating System Concepts

4.8

Silberschatz and Galvin 1999

Process Scheduling Queues

Job queue set of all processes in the system.

Device queues set of processes waiting for an I/O device.

Ready queue set of all processes residing in main memory,


ready and waiting to execute.
Process migration between the various queues.

Operating System Concepts

4.9

Silberschatz and Galvin 1999

Ready Queue And Various I/O Device Queues

Operating System Concepts

4.10

Silberschatz and Galvin 1999

Representation of Process Scheduling

Operating System Concepts

4.11

Silberschatz and Galvin 1999

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.

Operating System Concepts

4.12

Silberschatz and Galvin 1999

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.

Operating System Concepts

4.13

Silberschatz and Galvin 1999

Schedulers (Cont.)
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

4.14

Silberschatz and Galvin 1999

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.

Operating System Concepts

4.15

Silberschatz and Galvin 1999

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.

Operating System Concepts

4.16

Silberschatz and Galvin 1999

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 parents resources.
Parent and child share no resources.

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

Operating System Concepts

4.17

Silberschatz and Galvin 1999

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.

Operating System Concepts

4.18

Silberschatz and Galvin 1999

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.

Operating System Concepts

4.19

Silberschatz and Galvin 1999

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)

Operating System Concepts

4.20

Silberschatz and Galvin 1999

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.

Operating System Concepts

4.21

Silberschatz and Galvin 1999

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

Operating System Concepts

4.22

Silberschatz and Galvin 1999

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.

Operating System Concepts

4.23

Silberschatz and Galvin 1999

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

Operating System Concepts

4.24

Silberschatz and Galvin 1999

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.

Operating System Concepts

4.25

Silberschatz and Galvin 1999

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 messages
Sender must wait if link full.
3. Unbounded capacity infinite length
Sender never waits.

Operating System Concepts

4.26

Silberschatz and Galvin 1999

Exception Conditions Error Recovery

Process terminates
Lost messages
Scrambled Messages

Operating System Concepts

4.27

Silberschatz and Galvin 1999

You might also like