OS Process Managment

41
Processes Management

Transcript of OS Process Managment

Page 1: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 1/41

Processes Management

Page 2: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 2/41

Process Concept

An OS executes a variety of programs:

◦ Batch system Executes–

 jobs◦ Time-shared systems–user programs or tasks

◦ Textbook uses the terms job and process amost

interchangeabe!rocess–a program in execution" process

execution must progress in se#uentia fashion

◦ A process incudes:

 program counter

stack 

data section

Page 3: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 3/41

Process in Memory

Page 4: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 4/41

Process StateAs a process executes$ it changes state

◦ new: The process is being created◦ running: %nstructions are being executed

◦ waiting: The process is &aiting for some

event to occur ◦ ready: The process is &aiting to be

assigned to a processor 

◦ terminated: The process has finishedexecution

Page 5: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 5/41

PROCESS STATES

NEW

RUNNING

TERMINATE

REA!

WAITING

 A    M  I

  T  T  E  

INTERRUPT

E   "   

I   T   

     I    #    O     O

     R      E     $     E     N

     T 

     W   A     I     T

I                     #                     O                     O                    R                    E                    $                    E                    N                    T                    

W                    A                   I                    T                    

Page 6: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 6/41

Process Contro% &%oc' (PC&)

Aso caed as task contro bock'

%nformation associated &ith each process◦ !rocess state

◦ !rogram counter 

◦ (!) registers :- stack pointer $ genera purpose registers

◦ (!) scheduing information:-priority $ parameters◦ *emory-management information:- imit of tabe$ page and

segment tabe

◦ Accounting information :- (!) and rea time used $ time

imit◦ %+O status information :- i+o devices aocation for process

Page 7: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 7/41

Process Contro% &%oc' (PC&)

Page 8: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 8/41

i**erence +etween Process

and Program

,,

Page 9: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 9/41

Program

A program is a set of instructions

that are to perform a designatedtask 

,here as the program perform the

tasks directy reating to an

operation of a user ike &ord

 processing$ executing presentationsoft&are etc'

!rogram is an passive entity'

!rogram is a set of instructions that

resides in secondary memory'e& exampes:

◦ On a *icrosoft ,indo&s. system: The

/(acuator0 program is stored at

1:2&indo&s2system342cac'exe5'

◦ On a 6inux system: The /s0 program isavaiabe at: 1+bin+s5'

Process

The process is an operation &hich

takes the given instructions and

 perform the manipuations as per the

code$ caed /execution of

instructions0

A process is a modue that executesmodues concurrenty'

They are separate oadabe modues'

!rocess is an active entity'

!rocess is a set of programs under

execution and it resides in main

memory'

Exampe: Executing mutipe

instances of the /(acuator0

 program' Each of the instances aretermed as a process'

Page 10: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 10/41

Conte-t Switc.,hen (!) s&itches to another process$ the system

must save the state of the od process and oad thesaved state for the ne& process

State save and State 7estore

(ontext-s&itch time is overhead" the system does nousefu &ork &hie s&itching

,hen the context s&itch occurs the kerne saves the

context of the od process in its !(B and oads the

saved context of the ne& process schedued to runTime dependent on hard&are support

Page 11: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 11/41

CPU Switc. /rom Process to Process

Page 12: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 12/41

Process Sc.edu%ing 0ueues

1o+ 2ueue –set of a processes in the

systemReady 2ueue –set of a processes residing

in main memory$ ready and &aiting to

executee3ice 2ueues –set of processes &aiting

for an %+O device

!rocesses migrate among the various #ueues

Page 13: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 13/41

Ready 0ueue and $arious I#O e3ice 0ueues

Page 14: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 14/41

Representation o* Process Sc.edu%ing

Page 15: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 15/41

Sc.edu%ers

!rocess migrate among the various

scheduing #ueue%t must seect and processes for the

execution$ this is the function of Scheduer 

4ong5term sc.edu%er  8or job scheduer9–seects &hich processes shoud be brought

into the ready #ueue

S.ort5term sc.edu%er  8or (!) scheduer9–seects &hich process shoud be executed

next and aocates (!)

Page 16: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 16/41

Sc.edu%ersShort-term scheduer is invoked very

fre#uenty 8miiseconds9⇒

 must be fast6ong-term scheduer is invoked very

infre#uenty 8seconds$ minutes9⇒ may beso&

The ong-term scheduer contros the degreeof multiprogramming 

!rocesses can be described as either:◦

I#O5+ound process –

spends more time doing%+O than computations$ many short (!) bursts

◦ CPU5+ound process –spends more time doingcomputations" fe& very ong (!) bursts

Page 17: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 17/41

Addition o* Medium Term Sc.edu%ing

Page 18: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 18/41

Process Operation

!rocesses are created and deeted dynamicay!rocess &hich creates another process is

caed a parent  process" the created process is

caed a child  process'7esut is a tree of processes

e'g' )%; - processes have dependencies and form ahierarchy'

7esources re#uired &hen creating process (!) time$ fies$ memory$ %+O devices etc'

Process Creation65

Page 19: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 19/41

Process Creation

7esource sharing

!arent and chidren share a resources'

(hidren share subset of parent0s resources - prevents

many processes from overoading the system'

!arent and chidren share no resources'

Execution !arent and chid execute concurrenty'

!arent &aits unti chid has terminated'

Address Space (hid process is dupicate of parent process'

(hid process has a program oaded into it'

Page 20: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 20/41

UNI" Process Creation

ork system ca creates ne& processes

execve system ca is used after a fork to

repace the processes memory space &itha ne& program'

Page 21: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 21/41

Process Termination

!rocess executes ast statement and asks the

operating system to deete it 8exit 9'Output data from chid to parent 8via &ait9'

!rocess0 resources are deaocated by operatingsystem'

!arent may terminate execution of chid processes'

(hid has exceeded aocated resources'

Task assigned to chid is no onger re#uired'

!arent is exiting

OS does not ao& chid to continue if parentterminates

(ascading termination

T. d

Page 22: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 22/41

T.reads!rocesses do not share resources &e

high context s&itching overhead

A thread 8or ight&eight process9

 basic unit of (!) utii<ation" it consists of:  program counter$ register set and stack space

A thread shares the foo&ing &ith peer threads:

code section$ data section and OS resources 8open fies$ signas9

(oectivey caed a task'

=eavy&eight process is a task &ith one thread'

%t is simiar to a rea process but executes &ithin the context of a process and shares the same resources aotted to the process by the

kerne'

A process has ony one thread of contro > one set of machine

instructions executing at a time'

A process may aso be made up of mutipe threads of execution that

execute instructions concurrenty'

*utipe threads of contro can expoit the true paraeism possibe on

mutiprocessor systems'

On a uni-processor system$ a thread scheduing agorithm is appied

and the processor is schedued to run each thread one at a time'

Page 23: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 23/41

i**erence +etween Process

and T.reads

,,

Page 24: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 24/41

Process T.read

!rocesses are heavy &eight

operations'

Every process has its o&n

memory space'%nter process communication

is so& as processes have

different memory address'

(ontext s&itching bet&eenthe process is more

expensive'

!rocesses don0t share the

memory &ith other processes'

Threads are ight &eight

operations'Threads use the memory of the

 process they beong to'

%nter thread communication is

fast as threads of the same process share the same memory

address of the process they

 beong to'

(ontext s&itching bet&een

threads of the same process isess expensive'

Threads share the memory &ith

other threads of the same

 process'

Page 25: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 25/41

Operating System (oncepts

Cooperating Processes

 Independent  process cannot affect or beaffected by the execution of another process'

Cooperating  process can affect or be affected

 by the execution of another process

Advantages of process cooperation

◦ %nformation sharing

◦ (omputation speed-up

◦ *oduarity

◦ (onvenience

Page 26: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 26/41

Operating System (oncepts

Producer5Consumer Pro+%em

!aradigm for cooperating processes$ producer   process produces information that is

consumed by a consumer  process'

◦ unbounded-buffer  paces no practica imit on the

si<e of the buffer'

◦ bounded-buffer  assumes that there is a fixed buffer

si<e'

Page 27: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 27/41

Operating System (oncepts

Interprocess Communication (IPC)

*echanism for processes to communicate and to synchroni<etheir actions'

*essage system > processes communicate &ith each other

&ithout resorting to shared variabes'

%!( faciity provides t&o operations:◦ send8message9 > message si<e fixed or variabe

◦ recei3e8message9

%f P  and Q &ish to communicate$ they need to:

estabish a communication link  bet&een them◦ exchange messages via send+receive

%mpementation of communication ink 

◦ physica 8e'g'$ shared memory$ hard&are bus9

◦ ogica 8e'g'$ ogica properties9

Page 28: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 28/41

Operating System (oncepts

Imp%ementation 0uestions

=o& are inks estabished?(an a ink be associated &ith more than t&o

 processes?

=o& many inks can there be bet&een every pair of communicating processes?

,hat is the capacity of a ink?

%s the si<e of a message that the ink canaccommodate fixed or variabe?

%s a ink unidirectiona or bi-directiona?

Page 29: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 29/41

Operating System (oncepts

irect Communication

!rocesses must name each other expicity:◦ send 8 P, message9 > send a message to process !

◦ recei3e8Q, message9 > receive a message from

 process @

!roperties of communication ink 

◦ 6inks are estabished automaticay'

◦ A ink is associated &ith exacty one pair of

communicating processes'◦ Bet&een each pair there exists exacty one ink'

◦ The ink may be unidirectiona$ but is usuay bi-

directiona'

Page 30: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 30/41

Operating System (oncepts

Indirect Communication

*essages are directed and received from

maiboxes 8aso referred to as ports9'

◦ Each maibox has a uni#ue id'

◦ !rocesses can communicate ony if they share a

maibox'!roperties of communication ink 

◦ 6ink estabished ony if processes share a common

maibox

◦ A ink may be associated &ith many processes'◦ Each pair of processes may share severa

communication inks'

◦ 6ink may be unidirectiona or bi-directiona'

Page 31: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 31/41

Operating System (oncepts

Indirect Communication

Operations◦ create a ne& maibox

◦ send and receive messages through maibox

◦destroy a maibox

!rimitives are defined as:

send8 A, message9 > send a message to

maibox Arecei3e8 A, message9 > receive a message

from maibox A

Page 32: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 32/41

Operating System (oncepts

Indirect Communication

*aibox sharing◦ P 1 , P 2 , and P  share maibox A'

◦ P 1$ sends" P 2 and P  receive'

,ho gets the message?Soutions

◦ Ao& a ink to be associated &ith at most t&o

 processes'

◦ Ao& ony one process at a time to execute a receive

operation'

◦ Ao& the system to seect arbitrariy the receiver'

Sender is notified &ho the receiver &as'

Page 33: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 33/41

Sync.roni7ation

*essage passing may be either bocking ornon-bocking'

&%oc'ing is considered sync.ronous

Non5+%oc'ing is considered async.ronous

send and recei3e primitives may be either

 bocking or non-bocking'

Page 34: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 34/41

Page 35: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 35/41

Operating System (oncepts

C%ient5Ser3er Communication

Sockets7emote !rocedure (as

7emote *ethod %nvocation 8Dava9

Page 36: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 36/41

Operating System (oncepts

Soc'ets

A socket is defined as an endpoint forcommunication'

(oncatenation of %! address and port

The socket 898:;<:8=:>689;< refers to port89;< on host 898:;<:8=:>

(ommunication consists bet&een a pair of

sockets'

Page 37: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 37/41

Operating System (oncepts

Soc'et Communication

Page 38: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 38/41

Operating System (oncepts

Remote Procedure Ca%%s

7emote procedure ca 87!(9 abstracts procedure cas bet&een processes on

net&orked systems'

Stu+s > cient-side proxy for the actua procedure on the server'

The cient-side stub ocates the server and

marshalls the parameters'The server-side stub receives this message$

unpacks the marshaed parameters$ and

 peforms the procedure on the server'

Page 39: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 39/41

Operating System (oncepts

E-ecution o* RPC

Page 40: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 40/41

Operating System (oncepts

Remote Met.od In3ocation

7emote *ethod %nvocation 87*%9 is a Davamechanism simiar to 7!(s'

7*% ao&s a Dava program on one machine

to invoke a method on a remote object'

Page 41: OS Process Managment

7/25/2019 OS Process Managment

http://slidepdf.com/reader/full/os-process-managment 41/41

Mars.a%%ing Parameters