OS Section 03 Processes

download OS Section 03 Processes

of 20

Transcript of OS Section 03 Processes

  • 8/9/2019 OS Section 03 Processes

    1/20

    3: Processes 1

    Jerry Breecher

    OPERATING SYSTEMS

    PROCESSES

  • 8/9/2019 OS Section 03 Processes

    2/20

    3: Processes 2

    What Is In This Chapter?

    Process Definition Scheduling Processes What Do Processes Do?

    Inter-process Communication

    OPERATING SYSTEM

    Processes

  • 8/9/2019 OS Section 03 Processes

    3/20

    3: Processes 3

    PROCESSESPROCESS CONCEPT:

    A pro ra! is passive; a process active. Attributes held b a process include

    hard!are state" memor "

    CP#" progress $e%ecuting&

    W"Y "A#E PROCESSES?

    'esource sharing $ logical $files& and ph sical$hard!are& &.

    Computation speedup - ta(ing advantage of multiprogramming ) i.e. e%ample of acustomer*server database s stem.

    +odularit for protection.

    $e%initions

  • 8/9/2019 OS Section 03 Processes

    4/20

    3: Processes 4

    PROCESSES PROCESS STATE Ne& ,he process is ust being put together.

    R'nnin Instructions being e%ecuted. ,his running process holds the CP#. Waitin or an event $hard!are" human" or another process.&

    Rea(y ,he process has all needed resources - !aiting for CP# onl .

    S'spen(e( Another process has e%plicitl told this process to sleep. It !ill bea!a(ened !hen a process e%plicitl a!a(ens it.

    Ter!inate( ,he process is being torn apart.

  • 8/9/2019 OS Section 03 Processes

    5/20

    3: Processes 5

    PROCESS CONTRO) B)OC*:

    C/0,AI0S I0 /'+A,I/0 ASS/CIA,1D WI,2 1AC2P'/C1SS3

    It4s a data structure holding3

    PC" CP# registers" memor management information" accounting $ time used" ID" ... & I*/ status $ such as file resources &" scheduling data $ relative priorit " etc. & Process State $so running" suspended" etc. is simpl

    a field in the PC5 &.

    PROCESSES Process State

  • 8/9/2019 OS Section 03 Processes

    6/20

    3: Processes 6

    ,he act of Sche('+in a process means changing the active PC5 pointed to b the CP#. Also called a conte,t s&itch-

    A conte%t s!itch is essentiall the same as a process s!itch - it means that the memor "as seen b one process is changed to the memor seen b another process. See .i 're on Ne,t Pa e /0-12

    SC"E$3)ING 43E3ES:

    $Process is driven b events that are triggered b needs and availabilit &

    'ead 6ueue 7 contains those processes that are read to run.

    I*/ 6ueue $!aiting state & 7 holds those processes !aiting for I*/ service.

    What do the 6ueues loo( li(e? ,he can be implemented as single or double lin(ed.See .i 're Se5era+ Pa es %ro! No& /0-02

    PROCESSESSche('+inCo!ponents

  • 8/9/2019 OS Section 03 Processes

    7/20

    3: Processes 7

    PROCESSESSche('+inCo!ponents

    ,he CP# s!itchingfrom one process toanother.

  • 8/9/2019 OS Section 03 Processes

    8/20

    3: Processes 8

    .i 're 0-0

    PROCESSESSche('+inCo!ponents

    Rea(y 4An(

    IO 46s

  • 8/9/2019 OS Section 03 Processes

    9/20

    3: Processes 9

    )ONG TERM SC"E$3)ER

    'un seldom $ !hen ob comes into memor &

    Controls degree of multiprogramming

    ,ries to balance arrival and departure rate through an appropriate ob mi%.

    S"ORT TERM SC"E$3)ER

    Contains three functions3

    Code to remove a process from the processor at the end of its run.a&Process ma go to read 6ueue or to a !ait state.

    Code to put a process on the read 6ueue )a&Process must be read to run.b&Process placed on 6ueue based on priorit .

    PROCESSESSche('+inCo!ponents

  • 8/9/2019 OS Section 03 Processes

    10/20

    3: Processes 10

    S"ORT TERM SC"E$3)ER /cont-2

    Code to ta(e a process off the read 6ueue and run that process $also called(ispatcher &.

    a& Al!a s ta(es the first process on the 6ueue $no intelligence re6uired&

    b& Places the process on the processor.

    ,his code runs fre6uentl and so should be as short as possible.

    ME$I3M TERM SC"E$3)ER

    +i%ture of CP# and memor resource management.

    S!ap out*in obs to improve mi% and to get memor .

    Controls change of priorit .

    PROCESSESSche('+inCo!ponents

  • 8/9/2019 OS Section 03 Processes

    11/20

    3: Processes 11

    INTERR3PT "AN$)ER In addition to doing device !or(" it also readies processes" moving them" for

    instance" from !aiting to read .

    "o& (o a++

    thesesche('+in

    co!ponents%it to ether?

    .i 0-7

    PROCESSESSche('+inCo!ponents

    Interr'pt "an(+er

    Short Ter!Sche('+er

    Short Ter!Sche('+er

    )on Ter!Sche('+er

    Me(i'! Ter!Sche('+er

  • 8/9/2019 OS Section 03 Processes

    12/20

    3: Processes 12

    What nee(s to 8e (one on a process sche('+e?

    What nee(s to 8e (one on a threa( sche('+e?

    What is a conte,t s&itch?

    PROCESSESSche('+in Processes

    an( Threa(s

  • 8/9/2019 OS Section 03 Processes

    13/20

    3: Processes 13

    Parent can run concurrentl !ith child"or !ait for completion.

    Child ma share all $for(* oin& or partof parent4s variables.

    Death of parent ma force death ofchild.

    Processes are static $never terminate&or d namic $ can terminate &.

    In(epen(ent 1%ecution isdeterministic and reproducible.1%ecution can be stopped* started!ithout affecting other processes.

    Cooperatin 1%ecution depends onother processes or is time dependent.2ere the same inputs !on4t al!a sgive the same outputs; the processdepends on other e%ternal states.

    PROCESSESProcess

    Re+ationships

  • 8/9/2019 OS Section 03 Processes

    14/20

    3: Processes 14

    This is ho& processes ta+9 to each other-

    ,here are basicall t!o methods3

    Share( !e!ory $!ith a process 8(ic(8& -- fast* no data transfer.

    Messa e Passin -- distributed* better isolation.

    MET"O$S O. IMP)EMENTATION:

    Direct or indirect - to process or mailbo%. S mmetric or as mmetric? 5uffering mechanism Send b cop or b reference? i%ed or variable si9e messages?

    .3NCTIONA)ITY O. COMM3NICATION)IN*S:

    2o! are the lin(s formed? 2o! man processes on each lin(? 2o! man lin(s per pair of processes? Capacit - buffer space - can messages

    be en6ueued. +essage formats and si9es #ni- or bidirectional

    PROCESSESInterprocess

    Co!!'nication

  • 8/9/2019 OS Section 03 Processes

    15/20

    3: Processes 15

    $IRECT COMM3NICATION:

    0eed to (no! name of sender*receiver. +echanism loo(s li(e this3

    sen( $ Process:P" message & ;

    recei5e $ Process: " message &;

    recei5e $ id" message &

  • 8/9/2019 OS Section 03 Processes

    16/20

    3: Processes 16

    Other properties o% $irect Co!!'nication:

    =in( established automaticall $!hen send or receive re6uested.& /nl t!o processes in this form. /ne lin( per pair of processes. >enerall 5i-directional 'eceiver ma not need ID of sender.

    $isa(5anta e o% $irect Co!!'nication:

    ,he names of processes must be (no!n - the can4t be easil changed since the aree%plicitl named in the send and receive.

    PROCESSESInterprocess

    Co!!'nication

  • 8/9/2019 OS Section 03 Processes

    17/20

    3: Processes 17

    IN$IRECT COMM3NICATION

    Processes communicate via a named mailbo% rather than via a process name.+echanism loo(s li(e this3

    open $ mailbo%:name &; sen( $ mailbo%:name" message &; recei5e $ mailbo%:name" message&;

    =in( is established if processes have a shared mailbo%. So mailbo% must be establishedbefore the send*receive.

    +ore than t!o processes are allo!ed to use the same mailbo%.

    +a cause confusion !ith multiple receivers - if several processes have outstandingreceives on a mailbo%" !hich one gets a message?

    PROCESSESInterprocess

    Co!!'nication

  • 8/9/2019 OS Section 03 Processes

    18/20

    3: Processes 18

    B3..ERING:

    /ptions include3 ero -- sender must !ait for recipient to get message. Provides a rende9vous.

    Bo'n(e( -- sender must !ait for recipient if more than n messages in buffer.

    3n8o'n(e( -- sender is never dela ed.

    MESSAGE .ORMAT:

    i%ed" ariable" or , ped $as in language t ping& si9e messages.

    Send reference rather than cop $good for large messages&.

    Suspended vs. unsuspended sends.

    PROCESSESInterprocess

    Co!!'nication

  • 8/9/2019 OS Section 03 Processes

    19/20

    3: Processes 19

    Re!ote proce('re ca++ $'PC& abstractsprocedure calls bet!een processes onnet!or(ed s stems.

    St'8s ) client-side pro% for the actualprocedure on the server.

    ,he client-side stub locates the server andmarshalls the parameters.

    ,he server-side stub receives this message"unpac(s the marshalled parameters" and

    peforms the procedure on the server.

    PROCESSESInterprocess

    Co!!'nication

  • 8/9/2019 OS Section 03 Processes

    20/20

    3: Processes 20

    WRAP3P

    PROCESSES

    We65e +oo9e( in (etai+ at ho& processes &or9- Speci%ica++y &e65e

    @ Seen ho& they et sche('+e( /an( st'(ie( sche('+ers in (oin so2;@ #isite( the actions that can 8e per%or!e( on o8