1 CS153: Process Chengyu Song Slides modified from Harsha Madhyvasta, Nael Abu-Ghazaleh, and Zhiyun Qian
2 Administrivia Lab New TA Bojian Du Group info in process, will help the rest form groups Ask questions, piazza is preferred as other students may have the same one Lab1 will be released on this Friday (4/14) Survey Lab session time
3 OS abstractions Three major types of resources +-----------+----------------+-------------+ Process Virtual Memory File System +-----------+----------------+-------------+ Operating System +-----------+----------------+-------------+ Processor Memory Disk +-----------+----------------+-------------+
4 Class segments 1. Process, scheduling, and concurrency Basis for lab1 and midterm 2. Memory management 3. Persistence 4. Communication and security
5 What is a process (user perspective) Process is a program in execution Programs are static entities with the potential for execution Process is an active instance of a program Dynamic states: context, memory A program can have multiple instances A process is sometimes called a "job" or a "task"
6 What is a process (OS perspective) Process is the OS abstraction for execution A proxy of user OS interacts directly with processes Inherits user's privileges The only subject abstraction All other resources are abstracted as objects But a process itself is also an object The entity of resources allocation
7 Process components An address space and an ID (PID) Static Code and initial data (i.e., the program image) Dynamic Virtual memory allocated to the process: stack, heap, etc. Processor states: program counter (PC), general-purpose registers A set of operating system resources: opened files, network connections, etc.
Address space 8
9 Process states A process has an execution state that indicates what it is currently doing Running : executing instructions on the CPU It is the process that is currently using 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)
Process states graph 10
11 Process Data Structures Q: 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) PCB contains all of the info about a process
12 PCB PCB where OS keeps all of a process' related information Process ID (PID) Execution state Hardware state: PC, SP, regs Memory management Scheduling info: priority, statistics Security context etc
Xv6 struct proc 13
14 PCB in common OS Windows: EPROCESS Linux: task_struct (~500 LoC) macos, *BSD, Solaris: proc NOTE: real PCBs can be split into multiple data structures
15 PCBs and hardware state Hardware 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 The magician When the OS stops running a process, it saves the current hardware state to the PCB When the OS restarts the executing a process, it loads the previous hardware state from the PCB
16 Context switch The procedure of changing the hardware state from one process to another is called a context switch States changes between privilege levels are also referred as context switch User -> kernel (syscall)
17 State queues Q: 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 Running, 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
State queues (cont.) 18
19 PCBs and state queues PCBs are data structures dynamically allocated in OS memory When a process is created, the OS allocates a PCB for it, initializes it, and places it 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
20 Preview: process creation Creates and initializes a new PCB Creates and initializes a new address space Loads the program into the address space Initializes the address space and hardware state Initializes other OS resources Places the PCB on the ready queue
21 Summary What is a process? An execution of a program, an abstraction of execution What are the components of a process? PID, address space, static states, dynamic states What are the states of a process? Running, ready, wait, etc. How does of manages process Process control blocks (PCB), queues
22 For next class... Processes creation and scheduling Continue to get familiar with the lab environment Textbook Module 3, 4, 5, 6