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)

📋 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!

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