Process
1. Definition
A process is a program in execution — an active entity, whereas a program is a passive file on disk. When a program is loaded into memory and given a program counter, registers, a stack, a data area and the resources it needs, it becomes a process. The OS therefore defines a process as "a unit of work and the unit of resource ownership and protection".
2. Process vs Program
| Basis | Program | Process |
|---|---|---|
| Nature | Passive — a file of instructions | Active — a running instance |
| Storage | Exists on disk | Occupies main memory and CPU time |
| Lifetime | Until deleted | Created, executes, terminates |
| Copies | One file | Many processes can run from the same file |
| Contains | Code only | Code + PC + registers + stack + heap + resources |
| Cost | Disk space | RAM, CPU time, PCB, kernel bookkeeping |
Running the same editor program three times gives three independent processes with separate address spaces.
3. Process States and Transitions
┌───────────────────────────────────────────┐
│ │
NEW ──admitted──► READY ──dispatch──► RUNNING ──exit──► TERMINATED
▲ ▲ │
│ └─── pre-empted ◄──┤
│ │ I/O or event wait
│ ▼
└──── I/O or event completion ── WAITING (BLOCKED)
| State | Meaning |
|---|---|
| New | Process is being created; PCB allocated |
| Ready | Ready to run, waiting for the CPU in the ready queue |
| Running | Instructions are executing on the CPU (one per core) |
| Waiting / Blocked | Cannot proceed until an I/O completion, signal or resource becomes available |
| Terminated | Finished; resources are reclaimed |
Only one transition to RUNNING is possible per CPU core; READY → WAITING is impossible (a process cannot block while not running).
4. Process Control Block (PCB)
The kernel keeps one PCB (task control block) per process — the "identity card" of the process:
| Field | Content |
|---|---|
| Process ID (PID) and parent PID | Unique identifier, creator |
| Process state | new/ready/running/waiting/terminated |
| Program counter | Address of the next instruction |
| CPU registers | Accumulator, index, stack pointer, flags — saved on context switch |
| CPU scheduling information | Priority, time slice left, queue pointers |
| Memory management information | Base/limit registers, page-table or segment-table pointers |
| Accounting information | CPU time used, wall-clock time, limits, owner |
| I/O status | Open files, allocated devices, pending I/O |
5. Context Switch, Queues and Schedulers
- Context switch — the kernel saves the running process's PCB state and loads another's; it is pure overhead (microseconds), and its frequency depends on the quantum.
- Queues — job queue (all processes in the system), ready queue (in memory, ready to run), device queues (waiting for a particular device).
- Schedulers
- Long-term (job) scheduler — decides which jobs are admitted into memory; controls the degree of multiprogramming.
- Short-term (CPU) scheduler — picks the next process from the ready queue; runs on every dispatch/pre-emption (must be very fast).
- Medium-term scheduler — swaps processes out to disk (swapping) to relieve memory pressure.
- Scheduling criteria: CPU utilisation, throughput, turnaround, waiting and response time, fairness.
6. Process vs Thread
| Basis | Process | Thread |
|---|---|---|
| Definition | Independent program in execution | Lightweight unit of execution inside a process |
| Address space | Own, isolated | Shares the process's code, data and files |
| Creation cost | High (new address space, PCB) | Low (only stack, registers, PC) |
| Context switch | Expensive (memory map changes) | Cheaper (same address space) |
| Communication | Needs IPC (pipes, shared memory, sockets) | Direct through shared variables |
| Fault isolation | A crash affects only that process | One thread's fault can kill the whole process |
| Example | Chrome browser process per tab | Threads inside one tab (UI, network, renderer) |
7. Inter-Process Communication (IPC)
Processes are isolated, so they need OS mechanisms to exchange data: shared memory (fastest, needs synchronisation), pipes/FIFOs, message queues, sockets (across machines), signals, semaphores/mutexes for synchronisation, and files as a crude medium.
8. Exam Points
- Define a process. Differentiate a process from a program — 5 marks, almost certain.
- Draw and explain the process state transition diagram — 5-7 marks, very frequent.
- What is a PCB? List its fields with purpose — 5 marks, frequent.
- Explain long-term, short-term and medium-term schedulers — 5 marks.
- Differentiate processes and threads — 5 marks, frequent.
- What is a context switch and why is it overhead? — 3 marks.
- Name any four IPC mechanisms — 3 marks.