Chapter 1

Processes, threads and communication

A process combines an executing program with its current state and resources. This chapter separates process creation, execution and communication so that program traces can be counted correctly. Thread and system-call questions usually test what is shared and what changes.

1.1 System calls and privileged execution

Past papers · CS 2014–2026 (23 papers): 2 questions, 2 marks

A system call requests a kernel service through a controlled entry point. A library function can compute entirely in user mode, invoke one system call, or invoke several. The name of a C function alone does not determine the number of kernel entries. For example, strlen can run entirely in user space; malloc may reuse an existing arena or request more memory from the kernel. Normal process termination through exit ultimately enters the kernel. Sleeping for a positive interval requires kernel timer/scheduling support in the usual UNIX model.

Event or operationEssential distinction
System callSynchronous request caused by the executing program
Exception, such as a page faultSynchronous event associated with an instruction
Device interruptAsynchronous notification from hardware
Mode switchChanges execution privilege; may continue the same process
Context switchSaves one execution context and restores another
Timer interruptLets the OS regain control for preemptive scheduling

The kernel validates arguments and access rights before performing a service. Updating memory-protection registers, configuring a device directly, and disabling interrupts require privilege. A user program can request I/O through a system call without gaining unrestricted device access.

1.2 Process state and saved context

Past papers · CS 2014–2026 (23 papers): 5 questions, 5 marks

A ready process can execute once it receives the CPU. A blocked process must first wait for an event. In the basic five-state model, ready cannot move directly to blocked: it must run before issuing a blocking operation. Event completion changes blocked to ready; it does not bypass scheduling and force immediate execution.

The ready and blocked paths distinguish CPU waiting from event waiting.The ready and blocked paths distinguish CPU waiting from event waiting.

The process control block records identity, state, saved registers and program counter, scheduling data, memory-management references and I/O information. The program's code is passive; several processes may execute the same code with different data and saved contexts.

SchedulerDecision
Long-termWhich jobs enter the active population
Short-termWhich ready execution context gets the CPU
Medium-termWhich processes are suspended or restored

An interrupt may return to the same process; neither a timer tick nor another process's I/O completion necessarily selects a different process. An actual blocking call or disk-backed page-in takes the caller out of running state.

Suspended-ready and suspended-blocked states add memory residency to this model. Completion of an event can make a suspended-blocked process suspended-ready without bringing it into memory.

1.3 Fork, exec and wait

Past papers · CS 2014–2026 (23 papers): 3 questions, 5 marks

After a successful fork, both parent and child continue after the call. The return value is zero in the child and the child's positive process ID in the parent; failure returns −1 to the caller and creates no child. Ordinary private variables have separate logical copies. Copy-on-write may initially share physical pages.

For conditional forks, draw one branch per return path and evaluate short-circuit expressions separately. Count each print at the program point where it is reached: a print after every fork round contributes the population at each round, whereas a print after the whole loop counts only processes reaching the loop exit. A wait orders parent progress; it does not undo a child's later forks. && evaluates its right operand only if the left operand is nonzero; || evaluates it only if the left operand is zero.

A successful exec replaces the program image while retaining process identity; it does not return to the old instruction stream. wait/waitpid can collect a child's termination status. A zombie has terminated but still has status awaiting collection. An orphan has lost its parent and may still be executing; it is reparented.

1.4 Threads and what they share

Past papers · CS 2014–2026 (23 papers): 6 questions, 7 marks

Threads within a process share its address space and process resources. Each thread needs its own execution state. A thread's stack is logically private, but another thread can access it through a valid shared pointer in the same address space.

ItemThreads of one process
Code, global data, heapShared address space
Open file descriptorsShared process descriptor table
Program counter, registersSeparate execution state
Stack, thread IDSeparate per thread
Process page tableNormally shared
User-to-kernel mappingConsequence
Many-to-oneUser threads use one kernel thread; no multicore parallelism among them; a blocking kernel call can block that kernel thread
One-to-oneKernel schedules each thread; threads can run on separate cores
Many-to-manyUser threads are multiplexed over multiple kernel threads

User-thread creation or switching can avoid a kernel entry. Switching between threads of one address space need not change the page-table root. Switching processes may require that change; tagged TLB entries can reduce flushing.

1.5 IPC and ordering

Shared memory lets processes access a common region after setup; the processes must coordinate updates. Message passing transfers data through send/receive operations. A blocking receive waits for an appropriate message; a nonblocking receive can return without one. With zero buffering, a rendezvous requires sender and receiver to meet.

MechanismRevision cue
Anonymous pipeByte stream; close unused ends after fork
Named pipeA named communication endpoint for independently started processes
Shared memoryData sharing does not supply mutual exclusion
Message queue/mailboxMessages and naming/selection rules are part of the interface
SignalEvent notification; not a general bulk-data channel
SocketIPC endpoint, local or networked; protocol details belong to Networks

For a pipe, EOF occurs only after all write-end references are closed and buffered data has been consumed. Keeping an unused write end open can prevent a reader from observing EOF. A full pipe may block a writer; an empty pipe with a live writer may block a reader.

Last-minute recall

  • Kernel entry and process switching are different events.
  • A blocked process cannot be selected merely because the CPU is idle.
  • Fork resumes both paths after the call; exec replaces one path's program.
  • Count only forks actually reached by each process.
  • Private variables and inherited file offsets have different sharing rules.
  • Threads share an address space, not a single program counter.
  • Close unused pipe endpoints before reasoning about termination.

Revise offline: the whole Operating System handbook as one PDF

50 pages · 2.0 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections