Lecture 2OutlineWhat is a Process? 1What is a Process? 2Process StateProcess Control Block (PCB) 1Process Control Block (PCB) 2NEW -> READY 1NEW -> READY 2NEW -> READY 3NEW -> READY 4NEW -> READY 5NEW -> READY 6READY -> RUNNING 1READY -> RUNNING 2READY -> RUNNING 3RUNNING TransitionsRUNNING -> READY/WAITINGRUNNING -> TERMINATED 1RUNNING -> TERMINATED 2WAITING -> READYOther Process States 1Other Process States 2Wednesday, January 12 CS 470 Operating Systems - Lecture 2 1Lecture 2Code examples on csserver in directory /home/hwang/cs470/lecture02Questions?Wednesday, January 12 CS 470 Operating Systems - Lecture 2 2OutlineWhat is a process?Process statesProcess control blocksTransitions between process statesWednesday, January 12 CS 470 Operating Systems - Lecture 2 3What is a Process?Informally, a process is a program in executionFor now, assume process is sequential and single-threaded. I.e., only one instruction at a time is executed on behalf of a process. We will look at threads later.A process is active. There can be > 1 process per program. Also called a job.Wednesday, January 12 CS 470 Operating Systems - Lecture 2 4What is a Process?Process is more than just its code (text section).Includes the current activity context:program counterregistersstack & heap (temporary data)globals (data section)StackHeapDataTextWednesday, January 12 CS 470 Operating Systems - Lecture 2 5Process StateEach process has a state that may change as it executes. States have arbitrary names, but all states shown below are represented in all modern OS'sNEWREADY RUNNINGTERMINATEDWAITINGadmitteddispatchexitinterruptI/O or eventwaitI/O or eventcompletionWednesday, January 12 CS 470 Operating Systems - Lecture 2 6Process Control Block (PCB)What does a process need to keep track of?Unique ID (UID), parent's UID (PID), children's UIDsProcess stateProgram counter and registersCPU scheduling information, e.g., priorityMemory management information, e.g., stack pointerOther activity information, e.g., time usedI/O status, e.g., open filesWednesday, January 12 CS 470 Operating Systems - Lecture 2 7Process Control Block (PCB)Process information is stored in a process control block (PCB)Each PCB is stored in some "queue" in the system.Many systems have a hardware register dedicated to pointing to the current running process's PCB.Wednesday, January 12 CS 470 Operating Systems - Lecture 2 8NEW READYLook closer at the state transitions. A newly created process is in the NEW state.It transitions to the READY state when it is admitted into the system. Process is said to be put on the Ready Queue.NEWREADYadmittedWednesday, January 12 CS 470 Operating Systems - Lecture 2 9NEW READYIn batch systems, processes must wait to be admitted. Two phases of scheduling:Long-term (batch) scheduler determines the group to be admittedShort-term (process) scheduler determines which process in admitted group is dispatched to the CPU to be run.In time-sharing systems, i.e., most modern operation systems, new processes are admitted immediately, so there is only one (process) schedulerWednesday, January 12 CS 470 Operating Systems - Lecture 2 10NEW READYProcesses are created via a system call (e.g. fork( ) in Unix). The creating process is the parent; created process is the child.What does a new process need?PCB, memory, files, …Where does it get these resources from?Directly from the OSInherit from parentWednesday, January 12 CS 470 Operating Systems - Lecture 2 11NEW READYWhat happens to the parent process?Continue to execute concurrently with childWaits for some or all of children to terminateWhat program does the child run?Duplicate of parentSpecified programWednesday, January 12 CS 470 Operating Systems - Lecture 2 12NEW READYUnix - parent runs concurrently and child is a duplicate by default. Parent can execute wait( ). Child can execute exec( ).DEC VMS - parent runs concurrently and loads a specific program into the child.WinNT - parent runs concurrently and child can either be a duplicate or a specified program.Wednesday, January 12 CS 470 Operating Systems - Lecture 2 13NEW READYCode examples:Unix fork( ): newproc-posix.c (Figure 3.10)fork( ) returns 0 in child, child UID in parentchild starts executing the statement after the forkuses execlp( ) and wait( )Win32 CreateProcess( ): newproc-win32.c (Figure 3.12)10 parameters, including program image to loaduses WaitForSingleObjectWednesday, January 12 CS 470 Operating Systems - Lecture 2 14READY RUNNINGProcess transitions to the RUNNING state when it is dispatched to the CPU to be run.READY RUNNINGdispatchWednesday, January 12 CS 470 Operating Systems - Lecture 2 15READY RUNNINGIf there is a currently running process that is not exiting, its information must be saved (usually in its PCB) before the newly dispatched process can take over the CPU. This process is moved to an appropriate queue.The newly dispatched process information is loaded from its PCB, then starts executingCalled a context switch.Wednesday, January 12 CS 470 Operating Systems - Lecture 2 16READY RUNNINGThe process scheduler chooses a process on the Ready Queue to dispatch. It must support two objectives:use multiprogramming to maximize CPU utilizationswitch CPU between processes often enough so the users can interact with processesScheduling decisions must be fast, and context switches must be fast.Wednesday, January 12 CS 470 Operating Systems - Lecture 2 17RUNNING TransitionsA running process can leave the RUNNING state in one of three ways:READY RUNNINGTERMINATEDWAITINGexitinterruptI/O or eventwaitWednesday, January 12 CS 470 Operating Systems - Lecture 2 18RUNNING READY/WAITINGA running process may be interrupted. Since it is still able to be run, it goes back to the READY state.A running process may need to wait for some I/O or other event. The event ID (EID) is recorded in the process PCB and the process transitions to the WAIT state and is said to be put on the Wait Queue.In both these transitions, there is a context switch.Wednesday, January 12 CS 470 Operating Systems - Lecture 2 19RUNNING TERMINATEDA running process may exit to the TERMINATED state.Normal termination usually is done by calling an exit system call that releases
View Full Document