DOC PREVIEW
UE CS 470 - Lecture 2

This preview shows page 1-2-22-23 out of 23 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 23 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

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 11 CS 470 Operating Systems - Lecture 2 1Lecture 2Code examples on csserver in directory /home/hwang/cs470/lecture02Questions?Wednesday, January 11 CS 470 Operating Systems - Lecture 2 2OutlineWhat is a process?Process statesProcess control blocksTransitions between process statesWednesday, January 11 CS 470 Operating Systems - Lecture 2 3What is a Process?Informally, a process is a program in executionFor 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 11 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 counterregistersstack & heap (temporary data)globals (data section)StackHeapDataTextWednesday, January 11 CS 470 Operating Systems - Lecture 2 5Process StateEach process has a state that may change as it executes. States and transitions have arbitrary names, but all shown below are represented in all modern OS'sNEWREADY RUNNINGTERMINATEDWAITINGadmitteddispatchexitinterruptI/O or eventwaitI/O or eventcompletionWednesday, January 11 CS 470 Operating Systems - Lecture 2 6Process Control Block (PCB)What does a process need to keep track of?(Unique) process ID (PID), parent's PID (PPID), children's PIDsProcess stateProgram counter and registersCPU scheduling information, e.g., priorityMemory management information, e.g., stack pointerOther activity information, e.g., time usedI/O status, e.g., open filesWednesday, January 11 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 11 CS 470 Operating Systems - Lecture 2 8NEW  READYLook 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 11 CS 470 Operating Systems - Lecture 2 9NEW  READYIn batch systems, processes must wait to be admitted. Two phases of scheduling:Long-term (batch) scheduler determines the group to be admittedShort-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 operating systems, new processes are admitted immediately, so there is only one (process) scheduler.Wednesday, January 11 CS 470 Operating Systems - Lecture 2 10NEW  READYProcesses 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 OSInherit from parentWednesday, January 11 CS 470 Operating Systems - Lecture 2 11NEW  READYWhat happens to the parent process?Continue to execute concurrently with childWaits for some or all of children to terminateWhat program does the child run?Duplicate of parentSpecified programWednesday, January 11 CS 470 Operating Systems - Lecture 2 12NEW  READYUnix - 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 11 CS 470 Operating Systems - Lecture 2 13NEW  READYCode examples:Unix fork( ): newproc-posix.c (Figure 3.10)fork( ) returns 0 in child, child PID in parentchild starts executing the statement after the forkuses execlp( ) and wait( )Win32 CreateProcess( ): newproc-win32.c (Figure 3.12)10 parameters, including program image to loaduses WaitForSingleObjectWednesday, January 11 CS 470 Operating Systems - Lecture 2 14READY  RUNNINGProcess transitions to the RUNNING state when it is dispatched to the CPU to be run.READY RUNNINGdispatchWednesday, January 11 CS 470 Operating Systems - Lecture 2 15READY  RUNNINGIf 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 executingCalled a context switch.Wednesday, January 11 CS 470 Operating Systems - Lecture 2 16READY  RUNNINGThe process scheduler chooses a process on the Ready Queue to dispatch. It must support two objectives:use multiprogramming to maximize CPU utilizationswitch CPU between processes often enough so the users can interact with processesScheduling decisions must be fast, and context switches must be fast.Wednesday, January 11 CS 470 Operating Systems - Lecture 2 17RUNNING TransitionsA running process can leave the RUNNING state in one of three ways:READY RUNNINGTERMINATEDWAITINGexitinterruptI/O or eventwaitWednesday, January 11 CS 470 Operating Systems - Lecture 2 18RUNNING  READY / WAITINGA 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 11 CS 470 Operating Systems - Lecture 2 19RUNNING  TERMINATEDA running process may exit to the TERMINATED state.Normal termination usually is done by calling an exit


View Full Document
Download Lecture 2
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 2 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 2 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?