Vous êtes sur la page 1sur 7

9/10/2008

On a single CPU system…

Processes - A System View  Only one process can use the CPU at
a time
… But we want the appearance of every
Concurrency & Context Switching process running at the same time
Process Control Block  How can we manage CPU usage?
What's in it and why? How is it used? Who sees it?
5 State Process Model  “Resource Management”
State Labels. Causes of State Transitions. Impossible
Transitions.

Zombies and Orphans


Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

On a single CPU system… On a single CPU system…

 Your process is currently using the  Answer:


CPU  Nothing.
 Naively… Put the current process on 'pause'
 What is the O/S (most likely) doing?

 What are our options?


long count = 0;
while(count >=0)
count ++;

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

1
9/10/2008

O/S : I need the CPU Time Slicing

1. Time slicing  A Process loses the CPU when its


 Use a HW timer to generate a HW interrupt time quanta has expired
2. Multiprogramming
 Wait until the process issues a system call
 e.g., I/O request  Advantages?
3. Cooperative Multitasking  Disadvantages?
 Let the user process yield the CPU

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

Multiprogramming Cooperative Multitasking

 Wait until system call  Wait until the process gives up the
CPU
 Advantages?
long count = 0;
 Disadvantages?  Advantages? while(count >=0) {
count ++;
 Disadvantages? if(count % 10000 == 0)
yield();
}

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

2
9/10/2008

Context Switch: In a simple


O/S (no virtual memory) Context Switch

 Context switch  Overhead to re-assign CPU to another


 The act of user process
removing one
process from
the running
 What activities are required?
state and
replacing it with
another

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

Context Switch 2 State Model


Processes dispatch
 Overhead to re-assign CPU to another
user process enter
not
exit
running
 Capture state of the user's processes so running

that we can restart it later (CPU


Registers) pause
System
 Queue Management queue
enter dispatch exit
 Accounting processor
 Scheduler chooses next process What information
do we need to keep pause
 Run next process
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta
in the queue? Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

3
9/10/2008

Process Control Block (PCB) PCB (more)

 In-memory system structure  Inter-process communication


 User processes cannot access it  Signals

 Identifiers  Privileges
 CPU instructions, memory
 pid & ppid
 Processor State Information  Memory Management
 Segments, VM control 'page tables'
 User-visible registers, control and status, stack
 Scheduling information  Resource Ownership and utilization
 Process state, priority, …, waiting for event info

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

Five State Process Model Five State Process Model

 "All models are wrong. Some Models are  Running


 Currently executing
Useful"  On a single processor machine, at most one process in the
 George Box, Statistician “running” state
 Ready
 2 state model  Prepared to execute
 Too simplistic  Blocked
 What does “Not Running” mean?  Waiting on some event
 New
 7 state model  Created, but not loaded into memory
 Considers suspending process to disk  Done
 See Stallings 3.2  Released from pool of executing processes

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

4
9/10/2008

5 State Model - States 5 State Model - Transitions


 Null (nothing) to New
 New process creation

running done running done

new ready blocked new ready blocked

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

5 State Model - Transitions 5 State Model - Transitions


 New to Ready  Ready to Running
 Move to pool of  Chosen to run from
executable the pool of
processes running done processes running done

new ready blocked new ready blocked

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

5
9/10/2008

5 State Model - Transitions 5 State Model - Transitions


 Running to Ready  Blocked to Ready
 Preempted by OS  Resource is now available
 Running to Blocked
running done running done
 Request for an
unavailable resource
 Running to Done
 Terminated by the OS

new ready blocked new ready blocked

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

5 State Model - Transitions 5 State Model - Transitions


 Ready to Done normal or abnormal termination
 Terminated by parent
 Blocked to Done
running done selected to running done
 Terminated by parent
run
I/O
process created request
quantum
expired
new ready blocked new ready blocked

I/O complete

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

6
9/10/2008

Orphans and Zombies Orphans

 If the parent process dies no one is left


to take care of the child
 Child may consume large amounts of
resources (CPU, File I/O)
 Child Process is re-parented to the init
process
 init does not kill child but will wait for it.
 child continues to run and run…

Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

Zombies Take-away questions


 A Zombie is a child  Zombie Removal  What would happen if user processes
process that exited  Professional code
before it’s parent installs signal handler were allowed to disable interrupts?
called wait() to get (CS241 later lecture)
for signal SIGCHLD
the child’s exit status which issues a wait()
 Do not consume many call
 In a single CPU system what is the
resources maximum number of processes that
 Exit status (held in the
program control block) can be in the running state?
 Also adopted by the init
process

 Next: Thread Magic


Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta

Vous aimerez peut-être aussi