P2L1. Processes and Process Management Flashcards
What is a process?
An instance of an executing program. (e.g., In our toy shop metaphor, a process is like an order of toys.)
It has a state of execution (program counter, stack), parts and temporary holding area (data, register state, occupies state in memory), and may require special hardware (I/O devices)
How does an operating system represent a process?
An address space is an “in memory” representation of a process.
What is an application?
A program on disk, in flash memory, or in the cloud. It’s a static entity (i.e., it’s not executing) in contract to a process, which is an active entity.
What happens when an application is launched?
It’s loaded in memory and starts executing, then it becomes a process.
A process is an active entity, in contrast to an application, which is a static entity.
If the same program is launched more than once then multiple processes will be created. These processes will be executing the same program but they will have different state.
What does a process look like?
A process encapsulates all of the state of a running application (code, data, variables, etc.) Every element of the process state needs to be uniquely identified by it’s address.
An address space is an abstraction used to encapsulate all the process state.
What is an address space?
An address space is an abstraction used to encapsulate all the process state.
The address space is defined by a range of addresses from v0 to vMax. These are called virtual addresses because they don’t have to correspond to actual locations in the physical memory.
What is the relationship between virtual address space and physical address space?
The memory management hardware and the operating system components responsible for memory management (e.g., page tables) maintain a mapping between the virutal addresses and the physical addresses. This mapping decouples the layout of the data in the vitual address space with the layout of the data in the physical address space. That allows physical memory to not be dictated to by the data layout of processes that are executing.
If two processes, P1 and P2, are running at the same time, what are the virtual address space ranges they will have?
- P1: 0 - 32,00, P2: 32,001 - 64,00
- P1: 0 - 64,000, P2: 0 - 64,000
- P1: 32,001 - 64,000, P2: 0 - 32,00
P1: 0 - 64,000, P2: 0 - 64,000
Both P1 and P2 can have the exact same virtual address space range. The operating system will map P1 and P2’s virtual addresses to distinct physical addresses.
How does the OS know what a process is doing?
- program counter
- CPU registers
- stack pointer
The OS maintains a process control block (PCB) to manage all of this data.
What is a program counter?
A program counter indicates where the process is in a sequence of program instructions. It is maintained on the CPU in a register while a process is executing.
What is a CPU register?
A CPU register holds values necessary during process execution.
What is a stack pointer?
The top of the stack is defined by the stack pointer. The stack exhibits last in first out behavior so we need to know the top of the stack to properly add/remove items.
What is a process control block (PCB)?
A data structure that the OS maintains for every process it manages.
The PCB is created and initialized (e.g., the program counter will be set to the first instruction) when a process is created.
Some fields are updated when a process state changes (e.g., it requests more memory and virual address space is updated)
Some fields change too frequently (e.g., process counter) and may only be updated under certain conditions.
The CPU has a dedicated register to track the current program counter for the currently executing process. The CPU program counter gets updated on every instruction. The OS is responsible for collecting all the information the CPU maintains for a process and store it in the process controll block structure whenever a process is no longer running on the CPU.
How is a process control block (PCB) used?
When an OS manages a process it stores it PCB in memory. When the process is running the CPU registers will hold values that correspond to the state of PCB-P1. When P1 is interrupted or finishes and P2 starts running, the OS will save PCB-P1 in memory and restore PCB-P2 by updating the CPU registers with values that correspond to the state of PCB-P2.
What is a context switch?
The process control blocks for each process are stored in memory and the values in the CPU registers will change depending on which process is currently executing.
A context switch is the mechanism used by the operating system to switch the CPU from the context of one process to the context of another process.
Context switches are expensive!
- direct costs: number of cycles that have to be executed to load and store all the values of the process control blocks to and from memory.
- indirect costs: cache misses, which require visits to memory