Stop 02 · Linux & Command LineTopics · 4/11

Process Management

Part of the DevOps Roadmap

In short

The server feels slow and the app won't respond. First question: what is actually running, and what is hogging the CPU? Process tools answer that in seconds.

Viewing, monitoring and controlling running processes — ps, top/htop, kill, and understanding process states — essential for diagnosing a server that's slow or unresponsive.

The mascot stands behind a bank counter handing out token slips to a queue of customers.

Think of it like this

The bank token counter

Every customer at the bank gets a token number. The manager can see all tokens, who is taking too long, and can call security to remove someone stuck at the counter. In Linux, every running program gets a PID, and you are the manager.

Watch it happen

Every process has a parent

systemd (1)
sshd (812)
nginx (900)
bash (2201)
worker (901)
worker (902)
top (2250)

1/4PID 1 is systemd. It is the first process and the ancestor of everything else.

The big ideas

What you need to know

ps shows a snapshot

ps aux lists every process with its PID, user, CPU and memory. Pipe it to grep to find one.

top shows it live

top or htop refresh every second. Sort by CPU or memory to catch the hungry process.

kill sends signals

kill PID sends SIGTERM, a polite 'please stop'. kill -9 is SIGKILL, an instant stop with no cleanup.

Background jobs

Add & to run a command in the background. jobs lists them and fg brings one back.

See it in code

Walk through the code

bash
1ps aux --sort=-%cpu | head -5   # top 5 CPU users2pgrep -a node                   # find node processes3top                             # live view, press q to quit4 5kill 4321        # polite stop (SIGTERM)6sleep 57kill -9 4321     # force stop only if still running8 9nohup ./backup.sh > backup.log 2>&1 &

1/3Find who is eating CPU, look up processes by name, then watch everything live.

Always try plain kill first. A program that gets SIGTERM can finish writing files and close connections cleanly.

Save yourself the pain

Common mistakes

Oops

Reaching for kill -9 every time something misbehaves.

Do this instead

Use plain kill first. -9 gives no time to clean up, which can leave corrupted files or locked resources.

Oops

Killing a worker process and wondering why it keeps coming back.

Do this instead

A parent or systemd may restart it. Stop the service properly with systemctl stop instead.

Your mission

Catch a CPU hog

~15 min

Quick check

Why try kill PID before kill -9 PID?

Go deeper

  1. 1Practice using ps aux and top/htop to inspect running processes.
  2. 2Learn to kill a runaway process safely (SIGTERM before SIGKILL).
  3. 3Understand process states (running, sleeping, zombie) and what each implies.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge