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.
Learn Python, JavaScript, Java and more with free interactive lessons, real projects and AI-powered help. Beginner-friendly.
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.
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.
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.
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.
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.
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.
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.
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.