Lesson 1 of 15
Process Control Block
The Process Control Block
Every process in Linux is represented by a Process Control Block (PCB) — a struct that holds everything the kernel needs to know about a process. In the Linux source, this is called task_struct and lives in include/linux/sched.h.
A minimal PCB contains:
#define NEW 0
#define READY 1
#define RUNNING 2
#define WAITING 3
#define ZOMBIE 4
typedef struct {
int pid;
int state;
char name[32];
int priority;
} PCB;
- pid — process ID, unique identifier assigned by the kernel
- state — current lifecycle state of the process
- name — human-readable name (in Linux:
comm, 16 bytes max) - priority — scheduling priority (0 = highest in Linux's real-time range)
Your Implementation
Write void print_pcb(PCB *p) that prints each field on its own line:
PID: 1
Name: init
State: RUNNING
Priority: 0
Use a helper const char *state_name(int s) that maps the state integer to its string.
Your Task
Implement print_pcb that prints the PCB fields in the format shown above.
TCC compiler loading...
Loading...
Click "Run" to execute your code.