Processes and system calls
A process is the OS’s record of one executing program image, not merely a file on disk. Without process state, the kernel could not stop one task and resume another or collect its exit status. We will trace memory layout, PCB fields, state transitions, context switching, fork, exec and wait in dependency order.
#Section 5Processes and memory layout
Running ./server creates an executing process from a passive executable. The process owns an address-space view, an execution state and references to resources. Its text holds instructions, data holds initialized writable globals, BSS represents zero-initialized storage, the heap serves dynamic allocation, and the stack holds call frames. These regions are logical parts of one virtual address space, not promises that the bytes occupy adjacent physical RAM.
Stack objects live within their frames; heap allocations can outlive the requesting call under explicit ownership. A user-space allocator handles many requests before needing another kernel mapping.
When Finch’s child later calls exec, the process identity can remain while the old image disappears. That distinction lets a shell create a child, load a new program into it and still wait for the same child. A process is therefore a live contract around execution and resources, not an immutable executable format.
#Section 6Process control blocks
The scheduler cannot save “the process” as a vague idea. It needs a process control block, or PCB, containing the identity, state and execution details required to stop and resume it. The PCB conceptually stores a PID, program counter, CPU registers, stack pointer, scheduling data, memory-management references, open-resource links and accounting or security information.
The program counter names the next instruction. Registers hold temporary values that the calling convention and instruction set require. The address-space context tells the CPU which translations apply. Open-resource information connects descriptor numbers to files, sockets or pipes. Security information lets the kernel check the process’s identity and credentials when it requests an operation.
The PCB is not necessarily one public C struct with exactly these fields. Kernels split state across scheduler records, task structures, address-space objects and file tables. The conceptual grouping is useful because it explains why a context switch costs work in several subsystems, not only a register save.
#Section 7Process states
Finch’s process is ready when it can run but waits for a core, running while a core executes it, and blocked when it waits for an event such as a socket or disk completion. A new process first needs admission and setup. A terminated process has finished execution, but its exit status may remain until the parent collects it.
A timer can move running work to ready; blocking moves it to waiting. Completion makes waiting work ready, and the scheduler dispatches it. Preserve the cause of each transition.
For the server, 20 ready connections do not imply 20 running threads. On 2 cores, at most 2 tasks execute simultaneously, while the rest remain ready or wait on I/O. A useful trace records both the event and the queue, because “the process is slow” could mean CPU wait, lock wait, a page fault or a device wait.
#Section 8Context switching
When the scheduler changes from process A to process B, it saves A’s registers, program counter and stack pointer, selects B, restores B’s saved state and installs the relevant address-space context. A context switch is that change of execution context. It is necessary for sharing a core, but it is not productive application work.
Switching can disrupt cache and TLB locality as well as save registers. Address-space identifiers can preserve some translations, but register-save time alone still does not describe the cost.
A smaller time slice improves response but increases switch frequency. A larger slice lowers overhead but lets one task delay another. Multicore scheduling adds migration cost when moving a task to balance cores, especially when its cache data stays behind.