What Are Processes
Every program running on your system is a process. Your terminal? A process. The web browser? A process. Even ls becomes a process when you run it.
Programs vs Processes
- Program: A file on disk (executable code)
- Process: A running instance of a program
You can run the same program multiple times - each creates a separate process.
Process IDs (PIDs)
Every process has a unique number: its PID.
$$ is your current shell's PID. Each terminal session has a different PID.
Parent and Child Processes
When a process creates another process:
- Creator = parent
- New process = child
The child remembers its parent's PID (PPID):
Process Tree
All processes form a tree. At the top is PID 1 (init/systemd), the ancestor of everything.
Process States
A process can be in different states:
| State | Symbol | Meaning |
|---|---|---|
| Running | R | Actively using CPU |
| Sleeping | S | Waiting for something (interruptible) |
| Disk Sleep | D | Waiting for I/O (uninterruptible) |
| Stopped | T | Paused (e.g., Ctrl+Z) |
| Zombie | Z | Finished but not cleaned up |
┌─────────────┐
│ Created │
└──────┬──────┘
│
▼
┌─────────────┐
┌────────→│ Running │←────────┐
│ │ (R) │ │
│ └──────┬──────┘ │
│ │ │
Scheduled I/O wait Continues
│ │ │
│ ▼ │
│ ┌─────────────┐ │
└─────────│ Sleeping │─────────┘
│ (S/D) │
└──────┬──────┘
│
Ctrl+Z│ Exit
▼ │
┌─────────────┐ │
│ Stopped │ │
│ (T) │ │
└─────────────┘ ▼
┌─────────────┐
│ Zombie │
│ (Z) │
└─────────────┘
Most processes are sleeping - waiting for input, network, etc.
The init Process
PID 1 is special. It's the first process started by the kernel.
On modern Linux, this is usually systemd. It manages all other services.
Lifecycle of a Process
- Created - fork() or similar system call
- Running/Sleeping - doing its job
- Terminated - finished or killed
- Zombie (brief) - waiting for parent to acknowledge
- Removed - fully cleaned up
What's the relationship between a program and a process?
Key Takeaways
- A process is a running instance of a program
- Every process has a unique PID
- Processes form a tree with PID 1 at the root
- Processes can be running, sleeping, stopped, or zombie
- Your shell is a process that creates child processes for commands
Next: viewing processes with ps.