CSE325 Principles of Operating Systems Processes David P. Duggan dduggan@sandia.gov February 1, 2011
Today s Goal: 1. Process Concept 2. Process Manager Responsibilities 3. Process Scheduling 4. Operations on Processes 5. Cooperating Processes 6. Inter-process Communication 1/30/2011 CSE325 - Processes 2
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
Basic Abstractions Idea Program Abstract Machine Result Idea Program Abstract Machine Physical Machine Result Idea Program Abstract Machine Result 4
How Multiprogramming Works Process 1 Process 2 Process 3 Process 4 Processor Time-multiplexed CPU Space-multiplexed Memory 1/30/2011 CSE325 - Processes 5
Process Abstraction Data Program Process Stack Operating System Hardware Processor Executable Memory 1/30/2011 CSE325 - Processes 6
Implementing the Process Abstraction P i CPU P j CPU P k CPU P i Executable Memory P j Executable Memory P k Executable Memory OS interface 1/30/2011 CPU ALU Control Unit OS Address Space P i Address Space P k Address Space P j Address Space Machine Executable Memory 7
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
External View of the Process Manager Application Program wait() fork() exec() CreateThread() CloseHandle() CreateProcess() WaitForSingleObject() Device Mgr Process Mgr Memory Mgr File Mgr UNIX Device Mgr Process Mgr Memory Mgr File Mgr Windows Hardware 1/30/2011 11
Process Manager Overview Program Process Abstract Computing Environment Device Manager File Manager Memory Manager Protection Deadlock Synchronization Scheduler Process Description Resource Resource Manager Resource Manager Manager Devices Memory CPU Other H/W 12
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 13
Algorithms, Programs, and Processes Idea Execution Engine Algorithm Status Stack Files Files Files Source Program Binary Program Data Other Resources 1/30/2011 Process 14
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 15
Diagram of Process State Program 1/30/2011 CSE325 - Processes 16
UNIX State Transition Diagram Wait by parent Zombie Sleeping Done Request I/O Request Request Running Allocate Schedule Start I/O Complete Resume Runnable Uninterruptible Traced or Stopped Sleep 1/30/2011 CSE325 - Processes 17
Windows NT Thread States CreateThread Terminated Reinitialize Initialized Running Exit Wait Dispatch Activate Waiting Wait Complete Ready Wait Complete Transition Select Preempt Dispatch Standby 1/30/2011 CSE325 - Processes 18
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 1/30/2011 CSE325 - Processes 19
Process & Address Space Code Data Stack Resources Resources Resources Abstract Machine Environment Address Space 1/30/2011 CSE325 - Processes 20
The Address Space Address Space Address Binding Executable Memory Process Files Other objects 1/30/2011 21
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 1/30/2011 CSE325 - Processes 22
Process Control Block (PCB) 1/30/2011 23
Windows NT Process Descriptor NT Kernel NT Executive EPROCESS KPROCESS uint32 KernelTime; uint32 UserTime; Byte state; void *UniqueProcessId; 1/30/2011 CSE325 - Processes 24
CPU Switch From Process to Process 1/30/2011 CSE325 - Processes 25
Context Switching Interrupt Initialization 1 7 2 Process Manager Interrupt Handler 8 Executable Memory 3 9 4 P 1 5 P 2 6 P n 1/30/2011 26
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? 1/30/2011 CSE325 - Processes 27