Thuta Learning
AdvancedDevOps & Toolsbeginner

Managing Processes: kill, jobs, bg/fg

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand Managing Processes: kill, jobs, bg/fg without any of the intimidation
  • Get hands-on practice trying out the commands yourself in the terminal
  • See how these commands actually come in handy on a real server or project

Let's think about it this way for a second

kill PID sends a signal to a process ID telling it to 'stop' — by default (SIGTERM, signal 15), it's a polite request to 'save your work and shut down,' so it might not stop immediately. kill -9 PID (SIGKILL), on the other hand, means 'stop right now' — it forces a stop with no chance to save, so data can be lost, and it should really only be your last resort. To run a command in the background, just add & at the end, and you can keep using the terminal right away. jobs lists your background jobs, fg pulls a background job back into the foreground, and Ctrl+Z pauses a running process (it's a pause, not a kill).

Let's connect this to a real-world scenario

If you want to run a long-running script (say, a file download) in the background, type wget https://example.com/file.zip & — no need to keep the terminal tied up, and you can keep typing new commands right away. If a process hangs, find its PID with ps aux | grep <name> and try kill <PID> first; only reach for kill -9 <PID> if that doesn't work — force-quitting shouldn't be your first option.

Let's try it together in the terminal

bash
ps aux | grep myapp
kill 12345
kill -9 12345      # ယဉ်ကျေးစွာ မရရင်သာ

sleep 300 &
jobs
fg %1
You should see
After running kill 12345, running ps aux | grep myapp again shows that the process has disappeared.

5-minute try-it

Run sleep 100 & (a background job). List it with jobs, then stop it with kill %1.

A quick word of caution

Running kill -9 on a system-critical process (like init or systemd) can crash the whole system — double-check the PID carefully before you kill anything.

Easy traps

  • Always reaching for kill -9 as the default option — this can lose unsaved data; you should try SIGTERM (the default kill) first
  • Thinking kill PID means kill process name (kill myapp) and getting an error — you need the PID (a number), not the name (though the pkill command does accept names)

Now try it yourself

Run sleep 100 & (a background job). List it with jobs, then stop it with kill %1.

You'll know it worked when: After running kill 12345, running ps aux | grep myapp again shows that the process has disappeared.

Managing Processes: kill, jobs, bg/fg | Thuta Learning