Unformatted text preview:

6 3ULQFLSOHV RI 2SHUDWLQJ 6 VWHPV DOO Lecture 3 Processes Geoffrey M Voelker 3URFHVVHV This lecture starts a class segment that covers processes threads and synchronization 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 September 26 2001 CSE 120 Lecture 3 Processes 2 1 7KH 3URFHVV The process is the OS abstraction for execution 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 instruction at a time execution of a program Programs are static entities with the potential for execution September 26 2001 CSE 120 Lecture 3 Processes 3 3URFHVV RPSRQHQWV 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 A process is named using its process ID PID September 26 2001 CSE 120 Lecture 3 Processes 4 2 3URFHVV LDJUDP 0xFFFFFFFF Stack SP Address Space Heap Dynamic Memory Alloc Static Data Data Segment Code Text Segment PC 0x00000000 September 26 2001 CSE 120 Lecture 3 Processes 5 3URFHVV 6WDWH A process has an execution state that indicates what it is currently doing 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 Ready to execute but another process is executing on the CPU Waiting Waiting for an event e g I O completion It cannot make progress until event is signaled disk completes 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 September 26 2001 CSE 120 Lecture 3 Processes 6 3 3URFHVV 6WDWH UDSK Create Process New Ready Unschedule Process Terminated I O Done Schedule Process Running Waiting I O Page Fault etc Process Exit September 26 2001 CSE 120 Lecture 3 Processes 7 3URFHVV DWD 6WUXFWXUHV How does the OS represent a process in the kernel At any time there are many processes in the system each in its particular state The OS data structure representing each process is called the Process Control Block PCB The PCB contains all of the info about a process 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 September 26 2001 CSE 120 Lecture 3 Processes 8 4 3 DWD 6WUXFWXUH The PCB contains a huge amount of information in one large structure Process ID PID Execution state Hardware state PC SP regs Memory management Scheduling Accounting Pointers for state queues Etc Unix PCB is defined in sys proc h as struct proc FreeBSD 81 fields 408 bytes not lightweight September 26 2001 CSE 120 Lecture 3 Processes 9 3 V DQG DUGZDUH 6WDWH When a process is running its hardware state PC SP regs etc is in the CPU When the OS stops running a process it saves the current values of the registers into the process PCB When the OS is ready to start executing a new process it loads the hardware registers from the values stored in that process PCB The hardware registers contain the current values What happens to the code that is executing The process of changing the CPU hardware state from one process to another is called a context switch This can happen 100 or 1000 times a second September 26 2001 CSE 120 Lecture 3 Processes 10 5 6WDWH 4XHXHV How does the OS keep track of processes The OS maintains a collection of queues that represent the state of all processes in the system Typically the OS has one queue for each state Ready waiting etc Each PCB is queued on a state queue according to its current state As a process changes state its PCB is unlinked from one queue and linked into another September 26 2001 CSE 120 Lecture 3 Processes 11 6WDWH 4XHXHV Ready Queue Netscape PCB Disk I O Queue Emacs PCB X Server PCB Idle PCB ls PCB Console Queue Sleep Queue There may be many wait queues one for each type of wait disk console timer network etc September 26 2001 CSE 120 Lecture 3 Processes 12 6 3 V DQG 6WDWH 4XHXHV PCBs are data structures dynamically allocated in OS memory When a process is created the OS allocates a PCB for it initialized and placed on the ready queue As the process computes does I O etc its PCB moves from one queue to another When the process terminates its PCB is deallocated September 26 2001 CSE 120 Lecture 3 Processes 13 3URFHVV UHDWLRQ A process is created by another process In some systems the parent defines or donates resources and privileges for its children Parent is creator child is created Unix ps PPID field What creates the first process Unix init PID 0 or 1 Unix Process User ID is inherited children of your shell execute with your privileges After creating a child the parent may either wait for it to finish its task or continue in parallel or both September 26 2001 CSE 120 Lecture 3 Processes 14 7 3URFHVV UHDWLRQ 17 The system call on NT for creating a process is called surprisingly enough CreateProcess BOOL CreateProcess char prog char args simplified CreateProcess Creates and initializes a new PCB Creates and initializes a new address space Loads the program specified by prog into the address space Copies args into memory allocated in address space Initializes the hardware context to start execution at main or wherever specified in the file Places the PCB on the ready queue September 26 2001 CSE 120 Lecture 3 Processes 15 3URFHVV UHDWLRQ 8QL In Unix processes are created using fork int fork fork Creates and initializes a new PCB Creates a new address space Initializes the address space with a copy of the entire contents of the address space of the parent


View Full Document

UCSD CSE 120 - Processes

Documents in this Course
Threads

Threads

14 pages

Deadlocks

Deadlocks

19 pages

Paging

Paging

13 pages

Processes

Processes

18 pages

Threads

Threads

29 pages

Security

Security

16 pages

Paging

Paging

13 pages

Processes

Processes

32 pages

Lecture 2

Lecture 2

13 pages

Paging

Paging

8 pages

Threads

Threads

14 pages

Paging

Paging

13 pages

Paging

Paging

26 pages

Paging

Paging

13 pages

Lecture

Lecture

13 pages

Processes

Processes

14 pages

Paging

Paging

13 pages

Security

Security

17 pages

Threads

Threads

15 pages

Processes

Processes

34 pages

Structure

Structure

10 pages

Lecture 3

Lecture 3

13 pages

Lecture 1

Lecture 1

28 pages

Threads

Threads

15 pages

Paging

Paging

30 pages

Load more
Loading Unlocking...
Login

Join to view Processes 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 Processes 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?