Processes
By the end of this lesson you'll be able to see every program running on your machine, find a stuck app by its PID, stop it cleanly (or force it as a last resort), and run long jobs in the background that survive after you log out.
Part of the free Cli course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
What You'll Learn
1️⃣ Processes, PIDs & ps
A process is just a running program — your browser, a server, even the shell you're typing in. The operating system gives each one a unique PID (Process ID), a number you use to refer to it. The ps command lists processes. On its own it shows only yours in the current terminal; the classic ps aux shows every process with useful columns like %CPU and %MEM . Pipe it into grep to find one program by name.
2️⃣ Live Monitoring with top & htop
ps gives you a single snapshot. When you want to watch what's happening — which process is eating your CPU right now — use top , a live monitor that refreshes every couple of seconds. Inside top , press P to sort by CPU, M to sort by memory, and q to quit. htop is a friendlier, colour version with scrolling and mouse support — install it once and you'll never go back.
🎯 Your Turn: Find a Process's PID
Fill in the blanks marked ___ using the hints, then run it. You'll start a throwaway timer and track down its PID — the exact skill you need before you can stop anything.
3️⃣ Stopping Processes: kill & Signals
To stop a process you send it a signal — a short message the kernel delivers. kill PID sends SIGTERM (signal 15): a polite "please shut down" that lets the program save its work, close files, and free up ports. Only if a process ignores that and truly hangs do you reach for kill -9 PID , which sends SIGKILL (signal 9) — the kernel destroys it instantly, with no chance to clean up. Don't know the PID? killall name targets processes by exact name, and pkill -f "pattern" matches anywhere in the command line.
SIGTERM vs SIGKILL — get the order right
Always try kill PID (SIGTERM) first and give it a second or two. Reaching straight for kill -9 can corrupt files, leave locks behind, or strand a database mid-write, because the program never gets to finish what it was doing. kill -9 is the emergency brake, not the parking brake.
4️⃣ Foreground, Background & nohup
When you run a command normally it runs in the foreground and holds your terminal hostage until it finishes. Add a trailing & to run it in the background so you keep working. jobs lists this shell's background and paused jobs; fg pulls one to the foreground and bg resumes a paused one in the background. Press Ctrl+Z to pause whatever's in the foreground. One catch: a plain background job dies when you close the terminal (it receives SIGHUP ). Start it with nohup — "no hangup" — and it survives logout.
Pro Tip
nohup ... & is fine for a quick task, but for a real server you want it to restart on crash and start on boot. Reach for a process manager: pm2 for Node apps, or systemd services on Linux. tmux and screen are also great for keeping interactive sessions alive over SSH.
🎯 Your Turn: Background a Job, Then Reclaim It
Fill in the blanks, then run it. You'll send a timer to the background, confirm it's there with jobs , and pull it back to the foreground.
Common Errors (and the fix)
- Reaching for kill -9 first: SIGKILL gives the process no chance to save data or release ports, which can corrupt files. Always try kill PID (SIGTERM) first; use -9 only when it genuinely won't stop.
- Killing the wrong PID: PIDs get reused, and a quick glance is easy to misread. Confirm with ps -p PID or ps aux | grep name before you kill. Killing the wrong number can take down something important.
- Background job vanishes after logout: a plain command & receives SIGHUP and dies when the terminal closes. Start it with nohup command & so it keeps running.
- bash: kill: (1842) - No such process : that PID has already exited (or you mistyped it). Re-run ps aux | grep name to get the current PID.
- Operation not permitted : you're trying to kill a process owned by another user (often root). Re-run with sudo kill PID — but be doubly sure of the PID first.
📋 Quick Reference
Command
What it does
ps aux
List every running process with details
ps aux | grep name
Find a process by name (read its PID)
top / htop
Live, updating process monitor
kill PID
Graceful stop (SIGTERM) — try this first
kill -9 PID
Force kill (SIGKILL) — last resort
killall name / pkill -f pat
Kill by name / by command-line pattern
command &
Run in the background
jobs / fg %1 / bg %1
List jobs / foreground / background a job
nohup command &
Keep a job running after logout
Signal
Number
Meaning
SIGTERM
15
Polite "shut down" — the default for kill; allows cleanup
SIGKILL
9
Forced kill — cannot be caught or ignored; no cleanup
SIGHUP
1
"Hang up" — sent on terminal close; also "reload config"
SIGINT
2
Interrupt from the keyboard (Ctrl+C)
SIGSTOP
19
Pause a process (Ctrl+Z sends the related SIGTSTP)
SIGCONT
18
Resume a paused process
Frequently Asked Questions
Mini-Challenge: Launch, Inspect & Stop a Server
No blanks this time — just a brief and an outline. Write the commands yourself, run them in your terminal, and check the result against the expected note. This is the exact loop you'll run whenever a server misbehaves.
🎉 Lesson Complete!
- ✅ Every running program is a process with a unique PID
- ✅ ps aux lists processes; top / htop watch them live
- ✅ kill PID (SIGTERM) is graceful; kill -9 (SIGKILL) is a forced last resort
- ✅ killall and pkill -f stop processes by name or pattern
- ✅ & , jobs , fg , and bg move work between foreground and background
- ✅ nohup command & keeps a job alive after you log out
- ✅ Next lesson: Permissions and Users — chmod , chown , and managing access
Practice quiz
What is a PID?
- A file permission
- A unique number identifying a process
- A pipe operator
- A shell variable
Answer: A unique number identifying a process. A PID (Process ID) is the unique number the OS gives each process.
Which command lists every process on the machine with details?
- ps aux
- jobs
- cd
- pwd
Answer: ps aux. ps aux shows every process with columns like %CPU and %MEM.
Which signal does plain kill PID send by default?
- SIGKILL (9)
- SIGHUP (1)
- SIGTERM (15)
- SIGINT (2)
Answer: SIGTERM (15). kill sends SIGTERM (15), a polite request to shut down.
What does kill -9 PID do?
- Pauses the process
- Reloads its config
- Lists its threads
- Forcibly kills it with SIGKILL, no cleanup
Answer: Forcibly kills it with SIGKILL, no cleanup. kill -9 sends SIGKILL; the kernel destroys it instantly with no cleanup.
What does adding & to the end of a command do?
- Runs it in the background
- Deletes its output
- Runs it as root
- Repeats it
Answer: Runs it in the background. A trailing & runs the command in the background.
Which command lists the background and stopped jobs in this shell?
- ps
- jobs
- top
- kill
Answer: jobs. jobs lists this shell's background and paused jobs.
Which command keeps a job running after you close the terminal?
- bg
- fg
- nohup
- jobs
Answer: nohup. nohup (no hangup) lets a job survive logout by ignoring SIGHUP.
Which command brings job number 1 back to the foreground?
- bg %1
- kill %1
- jobs %1
- fg %1
Answer: fg %1. fg %1 pulls job number 1 to the foreground.
Why should you try kill before kill -9?
- SIGTERM lets the program save and clean up first
- kill -9 is slower
- kill -9 needs sudo
- They are the same
Answer: SIGTERM lets the program save and clean up first. SIGTERM is graceful; -9 gives no chance to save data or release ports.
Which tool gives a live, continuously updating view of processes?
- ps
- top
- cat
- echo
Answer: top. top is a live monitor that refreshes; ps is just a snapshot.
Continue this course
- Previous: Shell Scripting Basics
- Next: Permissions and Users