Unformatted text preview:

CSE 120 Principles of Operating Systems Fall 2000 Lecture 4 Processes Geoffrey M Voelker Processes l This lecture starts a class segment that covers processes threads and synchronization u u l 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 u What are the units of execution u 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 u u u October 2 2000 CSE 120 Lecture 4 Processes 2 1 The Process l The process is the OS abstraction for execution u u u l l 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 u It defines the sequential instruction at a time execution of a program u Programs are static entities with the potential for execution October 2 2000 CSE 120 Lecture 4 Processes 3 Process Components l A process contains all of the state for a program in execution u u u u u u u 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 l A process is named using its process ID PID October 2 2000 CSE 120 Lecture 4 Processes 4 2 Process Diagram 0xFFFFFFFF Stack SP Address Space Heap Dynamic Memory Alloc Static Data Data Segment Code Text Segment PC 0x00000000 October 2 2000 CSE 120 Lecture 4 Processes 5 Process State l A process has an execution state that indicates what it is currently doing u 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 u Ready Waiting to be assigned to the CPU u 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 l As a process executes it moves from state to state u u Unix ps STAT column indicates execution state What state do you think a process is in most of the time October 2 2000 CSE 120 Lecture 4 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 October 2 2000 CSE 120 Lecture 4 Processes 7 Process Data Structures How does the OS represent a process in the kernel l At any time there are many processes in the system each in its particular state l The OS data structure representing each process is called the Process Control Block PCB l The PCB contains all of the info about a process l 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 u 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 October 2 2000 CSE 120 Lecture 4 Processes 8 4 PCB Data Structure l The PCB contains a huge amount of information in one large structure l 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 u FreeBSD 81 fields 408 bytes not lightweight October 2 2000 CSE 120 Lecture 4 Processes 9 PCBs and Hardware State l When a process is running its hardware state PC SP regs etc is in the CPU u l l 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 u l 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 u This can happen 100 or 1000 times a second October 2 2000 CSE 120 Lecture 4 Processes 10 5 State Queues How does the OS keep track of processes l The OS maintains a collection of queues that represent the state of all processes in the system l Typically the OS has one queue for each state u l l 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 October 2 2000 CSE 120 Lecture 4 Processes 11 State Queues 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 October 2 2000 CSE 120 Lecture 4 Processes 12 6 PCBs and State Queues l l l l 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 October 2 2000 CSE 120 Lecture 4 Processes 13 Process Creation l A process is created by another process u u l In some systems the parent defines or donates resources and privileges for its children u l 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 October 2 2000 CSE 120 Lecture 4 Processes 14 7 Process Creation NT l The system call on NT for creating a process is called surprisingly enough CreateProcess BOOL CreateProcess char prog char args simplified l CreateProcess u u u u u u 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 October 2 2000 CSE 120 Lecture 4 Processes 15 Process Creation Unix l In Unix processes are created using fork int …


View Full Document

UCSD CSE 120 - Processes

Documents in this Course
Threads

Threads

14 pages

Deadlocks

Deadlocks

19 pages

Processes

Processes

14 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

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?