CSE 120 Principles of Operating Systems Winter 2007 Lecture 3 Processes Keith Marzullo and Geoffrey M Voelker Processes z This lecture starts a class segment that covers processes threads and synchronization z These topics are perhaps the most important in this class You can rest assured that they will be covered in the exams Today s topics are processes and process management What are the units of execution How are those units of execution represented in the OS How is work scheduled in the CPU What are the possible execution states of a process How does a process move from one state to another January 16 2007 CSE 120 Lecture 3 Processes 2 1 The Process z The process is the OS abstraction for execution z z It is the unit of execution It is the unit of scheduling It is the dynamic execution context of a program A process is sometimes called a job or a task or a sequential process A sequential process is a program in execution It defines the sequential sequential instruction at a time instruction at a time execution of a program Programs are static entities with the potential for execution January 16 2007 CSE 120 Lecture 3 Processes 3 Process Components z A process contains all of the state for a program in execution An address space The code for the executing program The data for the executing program An execution stack encapsulating the state of procedure calls The program counter PC indicating the next instruction A set of general purpose registers with current values A set of operating system resources Open files network connections etc z A process is named using its process ID PID January 16 2007 CSE 120 Lecture 3 Processes 4 2 Process Address Space 0xFFFFFFFF Stack SP Address Space Heap Dynamic Memory Alloc Static Data Data Segment Code Text Segment PC 0x00000000 January 16 2007 CSE 120 Lecture 3 Processes 5 Process State z A process has an execution state that indicates what it is currentlyy doing g Running Executing instructions on the CPU It is the process that has control of the CPU How many processes can be in the running state simultaneously Ready Waiting to be assigned to the CPU Waiting Waiting for an event e g I O completion Ready to execute but another process is executing on the CPU It cannot make progress until event is signaled disk completes z As a process executes it moves from state to state Unix ps STAT column indicates execution state What state do you think a process is in most of the time How many processes can a system support January 16 2007 CSE 120 Lecture 3 Processes 6 3 Process State Graph Create Process New Ready Unschedule Process Terminated I O Done Schedule Process Running Waiting I O Page Fault etc Process Exit January 16 2007 CSE 120 Lecture 3 Processes 7 Process Data Structures How does the OS represent a process in the kernel z At any time time there are many processes in the system system each in its particular state z The OS data structure representing each process is called the Process Control Block PCB z The PCB contains all of the info about a process z The PCB also is where the OS keeps all of a process hardware execution state PC SP regs etc when the process is not running This state is everything that is needed to restore the hardware to the same configuration it was in when the process was switched out of the hardware January 16 2007 CSE 120 Lecture 3 Processes 8 4 PCB Data Structure z The PCB contains a huge amount of information in one large structure z Process ID PID Execution state Hardware state PC SP regs Memory management Scheduling Accounting Pointers for state queues Etc It is a heavyweight abstraction January 16 2007 CSE 120 Lecture 3 Processes 9 struct proc Solaris One structure allocated per active process It contains all data needed about the process while the process may be swapped out Other per process data user h is also inside the proc structure Lightweight process data lwp h and the kernel stack may be swapped out typedef struct proc Fields requiring no explicit locking struct vnode p exec pointer to a out vnode struct as p as process address space pointer struct plock p lockp ptr to proc struct s mutex lock kmutex t p crlock lock for p cred struct cred p cred process credentials Fields protected by pidlock int p swapcnt number of swapped out lwps char p stat status of process char p wcode current wait code ushort t p pidflag flags protected only by pidlock int p wdata current wait return value pid t p ppid process id of parent struct proc p link forward link struct proc p parent ptr to parent process struct proc p child ptr to first child process struct proc p sibling ptr to next sibling proc on chain struct proc p psibling ptr to prev sibling proc on chain struct proc p sibling ns prt to siblings with new state struct proc p child ns prt to children with new state struct proc p next active chain link next struct proc p prev active chain link prev struct proc p nextofkin gets accounting info at exit struct proc p orphan struct proc p nextorph January 16 2007 p pglink process group hash chain link next struct proc p ppglink process group hash chain link prev struct sess p sessp session information struct pid p pidp process ID info struct pid p pgidp process group ID info Fields protected by p lock kcondvar t p cv proc struct s condition variable kcondvar t p flag cv kcondvar t p lwpexit waiting for some lwp to exit kcondvar t p holdlwps process is waiting for its lwps to to be held ushort t p pad1 unused uint t p flag protected while set flags defined below clock t p utime user time this process clock t p stime system time this process clock t p cutime sum of children s user time clock t p cstime sum of children s system time caddr t p segacct segment accounting info caddr t p caddr t p brkbase brkbase base address of heap size t p brksize heap size in bytes Per process signal stuff k sigset t p sig signals pending to this process k sigset t p ignore ignore when generated k sigset t p siginfo gets signal info with signal struct sigqueue p sigqueue queued siginfo structures struct sigqhdr p sigqhdr hdr to sigqueue structure pool struct sigqhdr p signhdr hdr to signotify structure pool uchar t p stopsig jobcontrol stop signal CSE 120 Lecture 3 Processes 10 5 struct proc Solaris 2 Special per process flag when set will fix misaligned memory references char p fixalignment Per process lwp and kernel thread stuff id t p lwpid most recently allocated lwpid int p lwpcnt number of lwps in this process int p lwprcnt number
View Full Document
Unlocking...