Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 ·...
Transcript of Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 ·...
1/30/2011 CSE325 - Processes 2
Today’s Goal:
1. Process Concept
2. Process Manager Responsibilities
3. Process Scheduling
4. Operations on Processes
5. Cooperating Processes
6. Inter-process Communication
Process Concept
Early systems allowed one program at a time Poor utilization of expensive hardware
Defn: A Process is an abstraction of a processor Process is also a program in execution
Tighter control and compartmentalization
Unit of work in modern time-sharing systems
Modern systems consist of a collection of processes
A program is static, a process is dynamic
1/30/2011 CSE325 - Processes 3
4
Basic Abstractions
Program ResultAbstractMachine
PhysicalMachine
AbstractMachineProgram Result
Idea
Idea
AbstractMachineProgram Result
… …Idea
1/30/2011 CSE325 - Processes 5
How Multiprogramming Works
Processor
Process 1
Process 2
Process 3
Process 4
Space-multiplexed Memory
Time-multiplexed CPU
1/30/2011 CSE325 - Processes 6
Process Abstraction
Operating System
Hardware
Data
Process
Stac
k
Processor
ExecutableMemory
Program
7
OSAddressSpace
Implementing the Process Abstraction
ControlUnit
OS interface
…
Mac
hine
Exe
cuta
ble
Mem
ory
ALU
CPUPi Address
Space
Pi CPU
Pi ExecutableMemory
Pk AddressSpace
…
Pk CPU
Pk ExecutableMemory
Pj AddressSpace
Pj CPU
Pj ExecutableMemory
1/30/2011
Formal Model
The process concept is used to model: The states of a system – state
Some sequence of status values – computation
Means of generating a class of such sequences – action function
State-variables Elementary quantities
Can assume well-defined values
State Mapping from state-variables into values
1/30/2011 CSE325 - Processes 8
Formal Model, contd
State Space Set of possible states for a given set of state-variables
Computation Sequence of states, starting with the initial state
Action Function Mapping from states into states
Process is a triple (S,f,I), where S: state space
f: action function in that state space
I <= S: set of initial states
1/30/2011 CSE325 - Processes 9
Formal Model, contd
A process generates all computations generated by its action function from its initial states
Intuitively the variable set is memory
a state gives the contents of memory
the action function is a program
If two processes have disjoint state variable sets, they cannot interact Communication among processes is modeled by shared variables
Multiple processes may share WHAT, acting on different variable sets
1/30/2011 CSE325 - Processes 10
11
External View of the Process Manager
Hardware
ApplicationProgram
Dev
ice
Mgr
Proc
ess M
gr
Mem
ory
Mgr
File
Mgr
UNIX
Dev
ice
Mgr
Proc
ess M
gr
Mem
ory
Mgr
File
Mgr
Windows
CreateThread()CreateProcess()CloseHandle()
WaitForSingleObject()
fork()
exec()wait()
1/30/2011
12
Process Manager Overview
Program Process
Abstract Computing Environment
FileManager
MemoryManager
DeviceManager
ProtectionDeadlock
Synchronization
ProcessDescription
CPU Other H/W
SchedulerResourceManagerResourceManagerResourceManager
MemoryDevices
13
Process Concept
An operating system executes a variety of programs: Batch system – jobs
Time-shared systems – user programs or tasks
We use the terms job and process almost interchangeably.
Process – a program in execution; process execution must progress in sequential fashion.
A process includes: program counter
stack
data section
14
Algorithms, Programs, and Processes
Data
FilesFilesFiles
OtherResources
Idea
Algorithm
SourceProgram
BinaryProgram
Execution Engine
Process
StackStatus
1/30/2011
1/30/2011 CSE325 - Processes 15
Process State
As a process executes, it changes state new: The process is being created.
ready: The process is waiting to be assigned to a processor.
running: Instructions are being executed.
waiting: The process is waiting for some event to occur.
terminated: The process has finished execution.
1/30/2011 CSE325 - Processes 16
Diagram of Process State
Program
1/30/2011 CSE325 - Processes 17
UNIX State Transition Diagram
Runnable
StartAllocate
Done
Zombie
Wait byparent
Running
Schedule
Request
SleepingRequest
UninterruptibleSleep
I/O Request
I/O Complete
Traced or Stopped
Resume
1/30/2011 CSE325 - Processes 18
Windows NT Thread States
Initialized
CreateThread
Ready
Activate
Sele
ct
Standby
Running
Terminated
Waiting
Transition
Reinitialize
Exit
Pree
mpt
Dispatch
WaitWait Complete
Wait Complete
Dispatch
1/30/2011 CSE325 - Processes 19
Address Space
Process must be able to reference every resource in its abstract machine
Assign each unit of resource an address Most addresses are for memory locations
Abstract device registers
Mechanisms to manipulate resources
Addresses used by one process are inaccessible to other processes
Say that each process has its own address space
20
Process & Address Space
Address Space
Code ResourcesResources
Abstract Machine Environment
Stack
DataResources
1/30/2011 CSE325 - Processes
21
The Address Space
Process
AddressSpace
AddressBinding
ExecutableMemory
Other objects
Files
1/30/2011
1/30/2011 CSE325 - Processes 22
Process Control Blocks (PCB)or Process Descriptors
Information (data structure) associated with each process. Process state
Program counter
CPU registers
CPU scheduling information
Memory-management information
Accounting information
I/O status information
23
Process Control Block (PCB)
1/30/2011
1/30/2011 CSE325 - Processes 24
EPROCESS
…void *UniqueProcessId;…
NT Executive
Windows NT Process Descriptor
KPROCESS…uint32 KernelTime;uint32 UserTime;…Byte state;
NT Kernel
1/30/2011 CSE325 - Processes 25
CPU Switch From Process to Process
26
Context Switching
ProcessManager
InterruptHandler
P1
P2
Pn
Executable MemoryInitialization
1
23
45
7Interrupt
8
9
6
1/30/2011
1/30/2011 CSE325 - Processes 27
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.
How to reduce context-switch overheads?