Short & clear revision notes · 7 topics
When you run any command in Linux, the system creates a process — an instance of a running program with its own special environment.
Every process is tracked by a unique PID (Process ID) — a five-digit number. No two processes share the same PID at the same time. PIDs eventually roll over and repeat once all numbers are used up.
💡 Every time you type a command, you start a process. Even
lsis a process.
- Runs connected to your terminal — takes input from keyboard, outputs to screen
- You cannot run anything else until it finishes
- Default behaviour for all commands
$ ls ch*.doc # runs in foreground — prompt returns only after it finishes- Runs disconnected from the keyboard
- You can keep using the terminal while it runs
- Add
&at the end of any command to run it in the background
$ ls ch*.doc & # runs in background
[1] 1234 # [job number] PIDWhen the background job finishes:
[1] + Done ls ch*.doc &
$ # prompt available immediately💡 If a background process needs keyboard input, it pauses and waits until you bring it to the foreground.
| Foreground | Background | |
|---|---|---|
| Terminal blocked? | Yes | No |
| How to start | Just run the command | Add & at the end |
| Good for | Quick commands | Long-running tasks |
The ps (process status) command shows running processes.
$ ps
PID TTY TIME CMD
18358 ttyp3 00:00:00 sh
18361 ttyp3 00:01:31 abiword
18789 ttyp3 00:00:00 ps$ ps -f
UID PID PPID C STIME TTY TIME CMD
amrood 6738 3662 0 10:23 pts/6 0:00 first_one
amrood 6739 3662 0 10:22 pts/6 0:00 second_one
amrood 3662 3657 0 08:10 pts/6 0:00 -ksh
amrood 6892 3662 4 10:51 pts/6 0:00 ps -f| Column | Meaning |
|---|---|
UID |
User ID — who is running this process |
PID |
Process ID |
PPID |
Parent Process ID — who started this process |
C |
CPU utilisation |
STIME |
Process start time |
TTY |
Terminal associated with the process |
TIME |
Total CPU time used |
CMD |
The command that started the process |
| Option | What it shows |
|---|---|
-a |
All users' processes |
-x |
Processes with no terminal |
-u |
Additional info (like -f) |
-e |
Extended information |
Press Ctrl+C to interrupt and stop it immediately.
Find the PID with ps, then use kill:
$ kill 6738 # send termination signal to PID 6738
TerminatedIf the process ignores a normal kill:
$ kill -9 6738 # force kill — cannot be ignored
Terminated
⚠️ kill -9is the nuclear option — the process gets no chance to clean up. Use it only when a normalkilldoesn't work.
Every process has a parent. Most commands you run have the shell as their parent. The PPID column in ps -f shows the parent's PID.
shell (PPID)
└── command you ran (PID) ← child process
When a parent process is killed before its child, the child becomes an orphan. Linux reassigns it to the init process (PID 1), which becomes its new parent.
When a child process finishes but the parent hasn't acknowledged it yet, the child becomes a zombie. It shows up in ps with state Z.
- It is dead and not using resources
- It still has an entry in the process table
- Eventually cleaned up when the parent reads the exit status
| Type | Situation | State in ps |
|---|---|---|
| Normal | Running as expected | S, R |
| Orphan | Parent died first | Adopted by init |
| Zombie | Finished but not cleaned up | Z |
A daemon is a background system process that:
- Usually runs with root permissions
- Has no controlling terminal (shows
?in theTTYcolumn ofps -ef) - Waits silently for something to happen (e.g. a print command, a network request)
$ ps -ef | grep "?" # daemons show ? in TTY column💡 Examples of daemons: print daemon (waits for print jobs), web server daemon (waits for HTTP requests), cron daemon (waits for scheduled tasks).
$ top- Updates frequently in real time
- Shows CPU usage, memory, load averages, and busy processes
- Interactive — press
qto quit
| Job ID | Process ID (PID) | |
|---|---|---|
| What it is | Short number assigned by the shell | Unique system-wide number |
| Scope | Only within your current shell session | System-wide |
| Used for | Managing background/suspended jobs | Killing or tracking any process |
| Example | [1] |
6738 |
💡 A single job can contain multiple processes. Using the job ID is easier than tracking each process individually.
Run in background:
command &
List processes:
ps # your processes
ps -f # full details
ps -a # all users
top # live monitor
Stop a process:
Ctrl+C # stop foreground process
kill PID # stop background process by PID
kill -9 PID # force kill (last resort)
Process states in ps:
R = Running
S = Sleeping (waiting)
Z = Zombie (dead but not cleaned up)
? = No terminal (daemon)
Linux Process Management Notes — for revision use