COMP30023 · Computer Systems
Processes and Threads
Week 2 develops the process abstraction and the thread model — the process control block, what threads share versus keep private, and the running/ready/blocked state machine. Naming the event behind each state transition (and why there is no Blocked → Running edge) and listing per-process versus per-thread state are standard exam short-answer questions.
What this chapter covers
- 01Process = a running program; the elements it bundles (threads, address space, files, sockets)
- 02Multiprogramming and pseudo-parallelism: one core, interleaved execution chosen by the scheduler
- 03Process creation (fork clones the address space; execve replaces the image) and the four termination causes
- 04The three process states Running / Ready / Blocked and the four legal transitions (no Blocked → Running)
- 05The Process Control Block (PCB) and the process table; the saved execution context (PC, SP, registers)
- 06Per-process (shared) state — address space, globals, heap, open files — vs per-thread (private) state — PC, registers, stack
- 07Single- vs multi-threaded memory layout: shared code/data/heap, one stack per thread
- 08Why threads: parallelism across cores and overlapping I/O with computation; threads vs processes trade-offs; PThreads API
Naming the process-state transitions
- +1Running → Blocked: the process issues a blocking request and cannot continue until an external event occurs — for example it calls read() on a socket with no data yet, or waits on I/O completion.
- +1Running → Ready: the scheduler preempts the process — its time quantum expired (a clock interrupt) or a higher-priority process became ready — so it is still runnable but temporarily set aside.
- +1Ready → Running: the scheduler dispatches this process onto the CPU, loading its saved context (PC, SP, registers) from its PCB.
- +1Blocked → Ready: the awaited event arrives (the I/O completes, the input becomes available), so the process becomes runnable again. There is no Blocked → Running edge because a blocked process's data is not yet ready and, even once it is, the CPU is a scarce resource the scheduler hands out only from the ready queue — so the process must first become Ready and then be selected to run.
Key terms
- Process Control Block (PCB)
- The OS data structure holding everything about one process: process ID, parent, memory-management info, open file descriptors, priority, CPU time used, and the saved execution context (PC, SP, control registers). The list of all PCBs is the process table.
- Thread
- A unit of execution within a process with its own PC, SP, registers, stack and state. All threads of a process share the address space (code, globals, heap) and open files; only the stack and registers are per-thread.
- Process states
- Running (using the CPU), Ready (runnable but waiting for the CPU) and Blocked (cannot run until an external event). Legal transitions: Running→Blocked, Running→Ready, Ready→Running, Blocked→Ready. There is no Blocked→Running.
- fork() vs execve()
- fork() creates a child process that is a clone of the parent — separate address space, same memory image, same open files; it returns 0 in the child and the child PID in the parent. execve() (the exec family) then replaces the running program with a new one (fresh stack, heap, data).
- Per-process vs per-thread state
- Shared by all threads (per-process): address space, global variables, heap, open files, child processes, signals. Private to each thread (per-thread): program counter, registers, stack, and thread state.
- Multiprogramming
- Keeping several processes in memory and switching the CPU among them quickly so they run in pseudo-parallel. A single core runs one process at a time; the scheduler decides which runs next, overlapping CPU work with I/O for efficiency.
Processes and Threads FAQ
What is the difference between a process and a thread?
A process is a running program with its own address space; a thread is a unit of execution inside a process. Threads of the same process share the code, global data, heap and open files, and each has only its own program counter, registers and stack. So threads are cheaper to create and switch between and share data easily, but they are less isolated — one faulty thread can crash the whole process, whereas separate processes are protected from each other.
What do threads share and what is private to each thread?
Shared (per-process): the address space (code, globals, heap), open files, child processes, signals and accounting info. Private (per-thread): the program counter, the CPU registers, the stack, and the thread's state (running/ready/blocked). A common exam phrasing is 'a multithreaded process differs from a single-threaded one in that it has a separate stack (and registers) per thread'.
Why is there no Blocked → Running transition?
Because becoming runnable and being scheduled are separate steps. When a blocked process's event arrives it becomes Ready, joining the pool of runnable processes; the scheduler then decides which Ready process gets the CPU next. Jumping straight from Blocked to Running would bypass that scheduling decision and could preempt whatever is currently running without the scheduler's involvement.
Why use multiple threads if one core runs them serially?
Two reasons. First, on a multi-core machine threads genuinely run in parallel, so a CPU-bound job (each thread handling part of a large array) finishes faster. Second, even on one core, threads let you overlap I/O with computation — while one thread blocks waiting for the network or disk, another uses the CPU (the classic multithreaded web-server pattern). On a single core a purely CPU-bound job gets no speed-up from threads and even pays context-switch overhead — a common exam trap.
Can AI help me with processes and threads in COMP30023?
Yes. Sia can trace a fork()/thread_create() snippet to count processes and threads, quiz you on the state-transition diagram, or explain the shared-vs-private memory model step by step, checking your reasoning as you go. It is a study aid for understanding the method — it does not complete your projects, quizzes, MST or exam, and University of Melbourne academic-integrity rules apply.
Exam move
The process-state machine and the thread memory model are almost guaranteed marks in the mid-semester test (the operating-systems half) and reappear in the final exam, so make the diagrams automatic. Redraw the Running/Ready/Blocked state graph with a concrete event on every arrow, and sketch the single- vs multi-threaded memory layout (shared code/data/heap, one stack per thread) until you can do it from memory. Build two short lists — the four process-creation events and the four termination causes, and the per-process vs per-thread state split — and rehearse the classic traps (no Blocked → Running; no speed-up from threads on a single core for a CPU-bound job). Bring a fork-counting snippet to a tutorial and confirm your count. This is foundational for scheduling, memory and the projects, so consolidating it weekly pays off across the subject and your WAM.
Working through Processes and Threads in COMP30023? Sia is AskSia’s AI Computer Science tutor — ask any COMP30023 Processes and Threads question and get a clear, step-by-step explanation grounded in how COMP30023 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.