CSE Roadmap

Core tier · about 3 hours · 6 parts

Part 3 of 6 · 2 min read

Process control block

In plain words: When the kernel takes the processor from a process, it must remember everything needed to continue later, exactly where it stopped. It keeps this in one record per process, the process control block (PCB). Some books say "task control block" for the same thing. Think of a bookmark and sticky notes in a library book: they say where the reader stopped and what they were doing.

A PCB holds:

Field What it stores
Process state New, ready, running, waiting, terminated
Process number The PID (Level 0, page 6)
Program counter The address of the next instruction
Registers The values in the processor's registers when the process stopped
Scheduling data Priority and the queues it sits in
Memory data Where its memory is and how addresses map (Level 6)
Accounting data Processor time used, time limits
I/O data Open files and devices
Family links The parent, and the list of children

In Linux the PCB is a C structure named task_struct, which holds all of this and links to the parent and the children. In the books it is shown as a small block of about a dozen fields. In the real kernel it has many more.

You can see a few of these fields from user space:

$ sleep 30 &
$ grep -E "^(Name|State|Pid|PPid)" /proc/220/status
Name:   sleep
State:  S (sleeping)
Pid:    220
PPid:   218

The state letter comes from the kernel's own record for that process. The same letter shows up in the STAT column of ps.

Process control block

A process control block (PCB) is a record kept by the kernel for each process. It holds everything needed to manage the process and to resume it after it was stopped: its state, PID, program counter and registers, scheduling data, memory-management data, accounting data, open files, and links to its parent and children.

Example: when the kernel stops a running process, it copies the registers into that process's PCB, and it copies them back when the process runs again.

Check yourself: 1. Which two PCB fields together say where to continue after a stop? 2. What is the Linux name of the PCB structure? 3. Which field would tell you how many files a process has open?