Introduction
The UNIX kernel uses several data structures to manage processes. These structures store everything the kernel needs to know about each process — its state, memory, open files, scheduling information, and more.
1. Process Table (proc structure)
- A global kernel table with one entry for every process in the system.
- The process table is always resident in memory (never swapped).
- Each entry contains information needed even when the process is NOT running.
Process Table Entry Fields:
| Field | Description |
|---|---|
| PID | Process ID |
| PPID | Parent Process ID |
| State | Current process state |
| UID / GID | User and Group IDs |
| Priority | Scheduling priority |
| Signal | Pending signals |
| Pointer to u-area | Link to the process's u-area |
| Event | Event the process is sleeping on (if sleeping) |
| CPU usage | Recent CPU usage (for scheduling) |
| Timer fields | Alarm timer, profiling timer |
| Pointers | Links to region table, parent, child, sibling processes |
2. U-Area (User Area / u structure)
- A per-process data structure that stores information needed only when the process is currently running or swappable.
- The u-area is part of the process's kernel stack space and can be swapped to disk along with the process.
U-Area Fields:
| Field | Description |
|---|---|
| Process table pointer | Back-pointer to the process table entry |
| User IDs | Real UID, Effective UID, Real GID, Effective GID |
| Signal handlers | User-defined signal handling functions |
| Terminal | Control terminal (tty) |
| Error field | Error code from last system call |
| Return value | Return value of last system call |
| I/O parameters | Current I/O operation details (address, offset, count) |
| File descriptors | Array of open file descriptors (User FD table) |
| Current directory | Inode of current working directory |
| Root directory | Inode of root directory for the process |
| File size limit | Maximum file size the process can create |
| Accounting info | CPU time used, start time |
3. Per-Process Region Table
- Maps a process's virtual address space to physical memory regions.
- Each process has its own region table.
- Each entry points to a region in the kernel's global region table.
Region Types:
| Region | Description |
|---|---|
| Text | Executable code (read-only, shareable) |
| Data | Initialized and uninitialized global variables |
| Stack | Process stack (grows dynamically) |
| Shared Memory | Shared memory segments (IPC) |
Relationship Between Structures
┌──────────────────┐ ┌──────────────────┐
│ Process Table │ │ Region Table │
│ Entry (proc) │ │ (per-process) │
│ │ │ │
│ PID, State, │ │ Text Region ──────►┐
│ Priority, │ │ Data Region ──────►├─► Physical
│ Signals, │ │ Stack Region─────►│ Memory
│ Pointer ────────┼──► │ │ (Regions)
│ to u-area │ └──────────────────┘
└──────────────────┘
│
▼
┌──────────────────┐
│ U-Area │
│ │
│ FD Table, │
│ Signal Handlers,│
│ Current Dir, │
│ Accounting, │
│ I/O Params │
└──────────────────┘
Process Table vs U-Area
| Aspect | Process Table | U-Area |
|---|---|---|
| Scope | Global (all processes) | Per-process |
| In Memory | Always | Only when process is in memory |
| Swappable | No | Yes (swapped with the process) |
| Accessed | Even when process is NOT running | Only when process IS running |
| Info Stored | State, PID, scheduling, signals | FD table, signal handlers, I/O, accounting |
Summary
- The Process Table stores minimal, always-needed info and is always in memory.
- The U-Area stores detailed, process-specific info and can be swapped.
- The Per-Process Region Table maps virtual addresses to physical memory.
- Together, these three structures give the kernel everything it needs to manage a process.