Process Descript ion and Cont rol 1 Process:t he concept Pr ocess - - PowerPoint PPT Presentation

process descript ion and cont rol
SMART_READER_LITE
LIVE PREVIEW

Process Descript ion and Cont rol 1 Process:t he concept Pr ocess - - PowerPoint PPT Presentation

Process Descript ion and Cont rol 1 Process:t he concept Pr ocess = a pr ogr am in execut ion Example pr ocesses: OS ker nel OS shell Pr ogr am execut ing af t er compilat ion www-br owser Pr ocess management by OS :


slide-1
SLIDE 1

1

Process Descript ion and Cont rol

slide-2
SLIDE 2

2

Process:t he concept

Pr ocess = a pr ogr am in execut ion

  • Example pr ocesses:

– OS ker nel – OS shell – Pr ogr am execut ing af t er compilat ion – www-br owser

Pr ocess management by OS :

– Allocat e r esour ces – Schedule: int er leave t heir execut ion (wat ch f or pr ocessor ut ilizat ion, r esponse t ime) – I nt er pr ocess communicat ion, synchr onizat ion (wat ch f or deadlocks; int er leaving, nondet er minism imply incr eased dif f icult ies!)

slide-3
SLIDE 3

3

Two-St at e Process Model

  • Pr ocess may be in one of t wo st at es

– Running, Not -r unning – Not -Running Pr ocess in a Queue

slide-4
SLIDE 4

4

What are not -running processes doing?

slide-5
SLIDE 5

5

Act ually t here are more queues …

Obser ve: I / O’s much slower t han CPU What if all pr ocesses ar e wait ing f or I O and all memor y is allocat ed? Or if not enough memor y f or all pr ocesses t o execut e? Or if ...

slide-6
SLIDE 6

6

Suspended Processes

I dea: Swap t hese processes t o disk t o f ree up more memory (t o admit new processes)

  • Blocked st at e becomes suspend st at e when

swapped t o disk

slide-7
SLIDE 7

7

Two Suspend St at es

slide-8
SLIDE 8

8

Reasons f or Process Suspension

e.g. t o prevent deadlock

slide-9
SLIDE 9
slide-10
SLIDE 10

10

OS Cont rol St ruct ures

What a pr ocess needs in or der t o execut e (pr ocess’ image):

  • Pr ogr am
  • Dat a
  • St ack
  • Pr ocess Cont r ol Block

(cont ext ; f or mult ipr ogr amming) The OS must keep:

  • I nf or mat ion about t he

cur r ent st at us of each pr ocess and r esour ce

  • Tables ar e const r uct ed f or

each ent it y t he oper at ing syst em manages

slide-11
SLIDE 11

11

Process Table (and ot her OS t ables)

Each ent r y:

  • Wher e pr ocess is

locat ed

  • At t r ibut es necessar y

f or it s management

– Process I D – Process st at e – Locat ion in memory – Et c: process cont rol block

  • Ot her t ables hold

r esour ce-specif ic inf o (zoom int o lat er ):

– How main/ secondary memory is allocat ed, – I / O device st at us, buf f er in memory,… – File st at us, locat ion, at t ribut es, …

slide-12
SLIDE 12

12

Process Cont rol Block

PCB cont ains:

  • I dent if ier s (pr ocess, par ent

pr ocess, user , … )

  • Pr ocessor St at e I nf or mat ion

(r egist er values: must be copied and r est or ed in st at e t r ansit ions: r unningr eady,… )

  • Ot her Pr ocess Cont r ol I nf or mat ion:

– Scheduling and St at e I nf ormat ion (priorit y, event await ed, … ) – Process memory t ables – Resources (open f iles, ownership, … ) – Links (t o ot her process in a queue, … ) – Privileges – …

slide-13
SLIDE 13

13

Process Creat ion

Examples:

  • Execut ion of a compiled user program
  • User logs on (shell st art s execut ing)
  • Process creat ion t o provide a service

(e.g. print ing: user execut es lpr)

  • A process creat es anot her process (e.g.

shell creat es lpr; user programs can creat e processes, as well)

OS must :

  • Assign a unique process ident if ier
  • Allocat e space f or t he process
  • I nit ialize process cont rol block
  • Set up appropriat e linkages

– “I nclude” t he process in t he syst em (in some queue(s), … )

slide-14
SLIDE 14

14

When t o Swit ch a Running Process

  • Clock int er r upt

– pr ocess has execut ed f or t he maximum allowable t ime slice

  • I / O int er r upt
  • Memor y f ault

– memor y addr ess is in vir t ual memor y so it must be br ought int o main memor y

  • Tr ap

– er r or occur r ed – may cause pr ocess t o be moved t o Exit st at e

  • Super visor call (or syst em call)

– such as f ile open

slide-15
SLIDE 15

15

Change of Process St at e (cont ext swit ching)

r unningot her

  • Save cont ext of pr ocessor including pr ogr am count er and
  • t her r egist er s (in PCB)
  • Move PCB t o appr opr iat e queue (r eady, blocked, …

)

  • Select anot her pr ocess f or execut ion
  • Updat e t he PCB of t he pr ocess select ed
  • Updat e memor y-management dat a st r uct ur es
  • Rest or e cont ext (in pr ocessor ) of t he select ed pr ocess
slide-16
SLIDE 16

16

Modes of Execut ion

  • User mode

– Less-pr ivileged mode – User pr ogr ams t ypically execut e in t his mode

  • Syst em mode, cont r ol mode, or ker nel mode

– Mor e-pr ivileged mode – Ker nel of t he oper at ing syst em

slide-17
SLIDE 17

17

Execut ion of t he Operat ing Syst em

  • Non-pr ocess Ker nel

– oper at ing syst em code is execut ed as a separ at e ent it y t hat oper at es in pr ivileged mode

  • Pr ocess-Based Oper at ing

Syst em

– maj or ker nel f unct ions ar e separ at e pr ocesses – Usef ul in mult i-pr ocessor or mult i-comput er envir onment

  • Execut ion Wit hin User

Pr ocesses

– oper at ing syst em sof t war e wit hin cont ext of a user pr ocess – pr ocess execut es in pr ivileged mode when execut ing oper at ing syst em code

slide-18
SLIDE 18

18

Threads

slide-19
SLIDE 19

19

Processes and Threads

mult it hr eading: mor e t han one ent it ies can possibly execut e in t he same r esour ce- (i.e. pr ocess-) envir onment (and collabor at e bet t er ) Unit of …

dispat ching is r ef er red t o as a t hr ead

r esour ce

  • wner ship is

r ef er red t o as a pr ocess or t ask

slide-20
SLIDE 20

20

A process has … A t hread has …

  • a vir t ual addr ess space which

holds t he pr ocess image

  • global var iables, f iles, child

pr ocesses, signals and signal handler s

  • an execut ion st at e,

st ack and cont ext (saved when not r unning)

  • access t o t he memor y

and r esour ces of it s pr ocess

– all t hreads of a process share t his

  • some per -t hr ead

st at ic st or age f or local var iables

slide-21
SLIDE 21

21

Suspension and t erminat ion

  • Suspending a process involves suspending all

t hreads of t he process since all t hreads share t he same address space

  • Terminat ion of a process, t erminat es all

t hreads wit hin t he process

slide-22
SLIDE 22

22

Benef it s of Threads

  • Since t hreads wit hin t he same process share

memory and f iles, t hey can communicat e wit h each ot her wit hout invoking t he kernel

  • May allow parallelizat ion wit hin a process:

– I / O and comput at ion t o over lap (r emember t he

hist or ical st ep f r om unipr ogr amming t o mult ipr ogr amming?)

– concur r ent execut ion in mult ipr ocessor s

  • Takes less t ime t o

– cr eat e/ t er minat e a t hr ead t han a pr ocess – swit ch bet ween t wo t hr eads wit hin t he same pr ocess

slide-23
SLIDE 23

23

Uses of Threads

  • Overlap f oreground (int eract ive) wit h

background (processing) work

  • Asynchronous processing (e.g. backup while

edit ing)

  • Speed execut ion (parallelize independent

act ions)

  • Modular program st ruct ure (must be caref ul

here, not t o int roduce t oo much ext ra

  • verhead)

Q: can one achieve parallelism wit hin a process but wit hout using t hreads?

slide-24
SLIDE 24

24

I mplement ing Threads in User Space

The kernel is not aware of t he exist ence of t hreads;

Fig: Tanenbaum, Modern OS, 2/ e

  • Run-t ime syst em (t hr ead-

libr ar y in execut ion) is r esponsible f or bookkeeping, scheduling of t hr eads

  • allows f or cust omised

scheduling

  • can r un on any OS
  • But : pr oblem wit h blocking

syst em calls (when a t hr ead blocks, t he whole pr ocess blocks; i.e ot her t hr eads of t he same pr ocess cannot r un)

slide-25
SLIDE 25

25

I mplement ing Threads in t he Kernel

Kernel maint ains cont ext inf ormat ion f or t he process and t he t hreads

Fig: Tanenbaum, Modern OS, 2/ e

  • Scheduling is done
  • n a t hr ead basis
  • Does not suf f er

f r om “blocking pr oblem”

  • Less ef f icient t han

user -level t hr eads (ker nel is invoked f or t hr ead cr eat ion, t er minat ion, swit ching)

slide-26
SLIDE 26

26

Hybrid I mplement at ions

Mult iplexing user-level t hreads ont o kernel- level t hreads

Fig: Tanenbaum, Modern OS, 2/ e

To combine t he advant ages of t he ot her t wo appr oaches

slide-27
SLIDE 27

27

slide-28
SLIDE 28

28

Examples:

  • Posix Pt hr eads: (I EEE) st andar d:

– Specif ies int er f ace – I mplement at ion (using user / ker nel level t hr eads) is up t o t he developer (s) – Mor e common in UNI X syst ems

  • Win32 t hr ead libr ar y:

– Ker nel-level libr ar y, windows syst ems

  • J ava t hr eads:

– Suppor t ed by t he J VM (VM: a r un-t ime syst em, a gener al concept , wit h deeper r oot s and pot ent ial f ut ur e in t he OS wor ld) – I mplement at ion is up t o t he developer s –e.g. can use Pt hr eads API or Win32 API , et c

slide-29
SLIDE 29

29

Examples (cont )

  • Solaris: hybrid model

– User -level t hr eads – Light weight pr ocesses – Ker nel t hr eads

  • W2K, XP: hybr id

model

– Thr ead: ker nel (use win32 API )

  • Fiber : user -level

t hr ead (libr ar y)

  • Linux: Only ker nel-

level – clone sys-call: uses par amet er s t o descr ibe amount of r esour ce shar ing – Clone can somet imes equal a f or k, i.e. new t hr ead can be ”new pr ocess”

slide-30
SLIDE 30

30

slide-31
SLIDE 31

31

Scheduler Act ivat ions

  • Goal – mimic f unct ionalit y of kernel t hreads

– gain per f or mance of user space t hr eads

  • Avoids unnecessary user/ kernel t ransit ions

– Ker nel assigns vir t ual pr ocessor s t o each pr ocess – ”signals” (make upcalls) t o r un-t ime syst em upon blocking and unblocking of (user -level) t hr eads – let s r unt ime syst em allocat e t hr eads t o pr ocessor s

  • Concern:

Fundament al reliance on kernel (lower layer) calling procedures in user space (higher layer)