What's the difference between a program and a process? It's the difference between a recipe and cooking!
- A program is a file of instructions on your storage. It does nothing by itself.
- A process is a program that is running. The OS loads it into RAM and gives it a number called a PID (process ID).
Today you will start, watch and stop processes yourself! ๐งช
๐งช Lab 1: meet your first processes
ps
You'll see a small table:
PID TTY TIME CMD
2145 pts/0 00:00:00 bash
2310 pts/0 00:00:00 ps
- PID is the process ID, a unique number
- CMD is the program that is running
The bash is the shell, listening to you. And ps is in the list too, because it was running when it looked!
Which PID is the shell you're typing in?
echo $$
$$ always means the PID of this shell.
๐งช Lab 2: start a process in the background
sleep 300 &
sleep 300does nothing for 300 seconds (5 minutes). It's a perfect practice process.- The
&at the end means run in the background, so you get your prompt back.
You'll see something like [1] 2455. That 2455 is the PID of your new process!
jobs
ps -o pid,ppid,stat,cmd -p $$
jobs lists your background jobs. And the ps command shows your shell with its parent (ppid), which is who started it, and its state (stat).
Now find your sleep process (use the PID you saw):
ps -o pid,ppid,stat,cmd -C sleep
The STAT column shows the process state:
| Letter | Meaning |
|---|---|
| R | Running or ready to run |
| S | Sleeping: waiting for something |
| T | Stopped |
| Z | Zombie: finished but not yet cleaned up ๐ง |
Your sleep should say S. It's waiting, using no CPU at all!
๐งช Lab 3: stop a process
kill 2455
(Use your PID instead of 2455.) Then check:
jobs
ps -C sleep
It's gone! The OS asked the process to finish, and it did. ๐
๐ก
killreally means send a message. The normal message is "please finish". If a process ignores you,kill -9is the strict version. Use it only on your own lab processes.
๐งช Lab 4: watch all processes live with top
top
top is a live scoreboard of every process. It updates every few seconds.
Look at the columns:
- PID the process ID
- %CPU how much CPU it's using
- %MEM how much RAM it's using
- COMMAND the program name
Press q to quit top. (Press M to sort by memory, P to sort by CPU.)
๐งช Lab 5: everyone gets their own room
ps aux | head -10
This lists processes from every user. Look at the USER column: you'll see root (the system's boss) and your user name. Notice the PID numbers are all different. The OS gives every process its own protected memory, so one crashing program can't wreck the others.
๐ฆ Force Quit on your desktop does the same thing as
kill: it asks the OS to stop a stuck process.
Words to know
| Word | What it means |
|---|---|
| Process | A program that is running |
| PID | The process's unique ID number |
| Parent (PPID) | The process that started this one |
Background (&) |
Running without blocking your prompt |


