In this guide
Linux Process Management Explained: ps, top, Signals and systemd Services
Open a terminal on any Linux machine and run a few commands, and you are already managing processes. Every program that runs — your shell, your editor, your web server — is a process. When something hangs, eats all the CPU, or refuses to stop, the fix is almost never a reboot. It is knowing how to look at the process table, understand what a process is doing, and tell it what to do next.
This guide covers the whole workflow: what a process is, how to read ps and top, how signals work, how job control and priorities work, what zombie and orphan processes really are, and how systemd services fit into the picture.
The problem: a black box that eats your machine
A common student experience goes like this. A program you wrote starts looping, the laptop fan spins up, everything slows down, and the only response you can think of is holding the power button. Or a server process you started over SSH keeps running after you log out, and you have no idea how to stop it. Or a service that should start at boot does not, and its logs are nowhere obvious.
All three situations are process management problems, and all three have calm, precise fixes once you can see what is running and send the right signal.
How it works: processes, PIDs, and parents
A process is a running instance of a program, with its own memory, open files, and execution state. The kernel gives every process a unique process ID (PID). When a process starts another program, it becomes the parent, and the new process gets a parent process ID (PPID). This parent-child tree is why tools like pstree are useful: they show which process launched which.
A process is always in one state. The ones you will meet most often are:
- R (running or runnable): on a CPU right now, or waiting for one.
- S (sleeping): waiting for something, usually input or a timer. Most idle processes sit here.
- D (uninterruptible sleep): waiting on disk I/O. A process stuck here cannot be killed, even with SIGKILL — it clears once the I/O finishes.
- T (stopped): paused, usually by Ctrl+Z or a debugger.
- Z (zombie): finished, but its parent has not collected its exit status yet.
Step by step, the mental model is: find the process, read its state, decide what it needs, and only then act.
Step 1: see what is running with ps
ps prints a snapshot of the process table. Two views are worth memorising.
ps aux
ps -ef
ps aux shows, for each process, the user, PID, percentage of CPU and memory, virtual and resident memory sizes, terminal, state, start time, elapsed CPU time, and the command. Read it like this: a high %CPU column means the process is actively computing; a high %MEM column means it is holding a lot of memory. The STAT column holds the state letters above, sometimes with extras — s means a session leader, + means it is in the foreground of its terminal.
ps -ef shows the same idea with a different layout, including PPID, which makes parent-child relationships visible. To narrow the list, filter it:
ps aux | grep python
ps -ef --forest
The --forest option draws the parent-child tree with ASCII lines, which is the quickest way to answer "which process started this one?"
Step 2: watch live behaviour with top and htop
ps is a snapshot; top is a live view that refreshes every few seconds. Its header shows load averages, task counts by state, CPU usage broken into user, system, and idle percentages, and memory and swap totals. Below that is the process list, sorted by CPU by default.
Learn to separate two numbers that beginners confuse. Load average is the average number of processes runnable or waiting on I/O over the last 1, 5, and 15 minutes — it is a queue length, not a percentage, and on a multi-core machine a load of 4.0 is not necessarily a problem. CPU percentage is per-process: 100% means one full CPU core is busy, and a multi-threaded process can exceed 100%.
Inside top, press M to sort by memory, P to sort by CPU again, and k to send a signal to a process by PID. htop, if installed, is the same idea with colours, a tree view toggled by F5, and mouse support — worth installing on your own machine, though top is what you will find everywhere.
Step 3: send signals — the polite way first
Signals are the kernel's way of telling a process something happened. The three you will use most:
- SIGTERM (15): "please stop." The default for the
killcommand. The process can clean up: close files, save state, release locks. - SIGKILL (9): "stop right now, no cleanup." The process cannot catch or ignore it. Use it only when SIGTERM fails.
- SIGHUP (1): originally "your terminal hung up." Many daemons treat it as "reload your configuration," which is why restarting a web server's config often means
kill -HUPrather than a full restart.
The command is named kill, but it sends any signal, not just death:
kill 1234
kill -TERM 1234
kill -HUP 1234
The first two are equivalent — SIGTERM is the default. Always try SIGTERM first and wait a few seconds. SIGKILL is a last resort because the process gets no chance to flush buffers or release locks, which can leave a half-written file or a stale lock behind. If you must use it:
kill -KILL 1234
kill -9 1234
killall and pkill send a signal by name instead of PID. pkill matches against the process name, and pgrep lists matching PIDs first so you can check before you signal anything:
pgrep -a python
pkill -TERM python
Always run pgrep first. Signalling by name is convenient and dangerous in equal measure — a broad pattern can match processes you did not intend to stop.
Step 4: foreground, background, and job control
When you run a command, it runs in the foreground: your shell waits for it. Append & and it runs in the background while you keep using the shell. That is the start of job control, and three more keys complete it:
- Ctrl+Z suspends the foreground job (sends SIGTSTP, a stop signal).
bgresumes a suspended job in the background.fgbrings a background job back to the foreground.jobslists the shell's jobs with numbers.
sleep 300 &
jobs
fg %1
Try it with sleep: start a long sleep in the background, list jobs, and bring it forward. One catch matters for servers: a background job is still attached to your terminal session. When you log out of SSH, the shell sends SIGHUP to its jobs, and they die. For anything that must survive logout, use a terminal multiplexer like tmux or screen, or run it as a systemd service, covered below — not nohup as a permanent habit.
Step 5: priorities with nice and renice
Every process has a niceness value from -20 (highest priority) to 19 (lowest). A higher niceness means the process politely yields CPU to others. Start a CPU-heavy job at low priority with nice, or adjust a running process with renice:
nice -n 10 python train.py
renice -n 5 -p 1234
Only the root user can set negative niceness. Niceness only matters when CPUs are contended — a nice value does not cap a process, it just decides who wins when there is a queue.
Zombies and orphans, demystified
A zombie process has already finished. Its entry stays in the process table only because its parent has not yet read its exit status. Zombies hold almost no resources — no memory, no CPU — so a few of them are harmless. A growing pile of zombies means the parent program has a bug: it keeps forking children without reaping them. The fix is at the parent, not the zombie; you cannot kill a process that is already dead. Stopping or restarting the parent clears its zombies.
An orphan is the opposite: its parent died before it did. The kernel reparents orphans to PID 1 (systemd on most modern systems), which reaps them properly. Orphans are normal and usually harmless — daemon processes are deliberately orphaned this way.
Step 6: systemd services
On most modern distributions, PID 1 is systemd, and long-running programs are managed as services. The systemctl commands you need most:
systemctl status nginx
systemctl start nginx
systemctl stop nginx
systemctl enable nginx
systemctl disable nginx
status shows whether the service is active, its recent log lines, and its main PID. start and stop affect the current boot only; enable and disable control whether it starts automatically at boot. That distinction trips up many beginners: starting a service does not make it start at boot, and enabling it does not start it right now.
Logs live in the systemd journal, queried with journalctl:
journalctl -u nginx
journalctl -u nginx -f
journalctl -u nginx --since today
The -f flag follows new lines live, like tail -f. When a service fails, read systemctl status first for the exit code, then the journal for the actual error message — the two together almost always name the cause.
A minimal unit file shows how little a service definition needs. This one runs a small script at boot:
[Unit]
Description=My demo service
After=network.target
[Service]
ExecStart=/usr/local/bin/demo.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
ExecStart is the command, Restart=on-failure retries it if it crashes, and WantedBy ties it to normal multi-user boot. After writing a unit file, run systemctl daemon-reload, then systemctl enable --now to enable and start it in one step.
Debugging workflow: a runaway process, end to end
Put it together. A process is eating a CPU core and the machine feels slow:
- Run
topand confirm which PID is at the top of the CPU list, and whether it is really CPU (not I/O wait or memory pressure). - Run
ps -ef --forestorps -o pid,ppid,stat,cmd -p <pid>to see what the process is and what started it. - Check its logs — the application log, or
journalctl -u <service>if it is a service. - Send SIGTERM with
kill <pid>and wait a few seconds. - If it is still there, check whether it is in D state (waiting on I/O — wait, do not force it) or genuinely ignoring the signal.
- Only then send SIGKILL, and check the parent and the logs afterwards for what went wrong.
- If it keeps coming back, the problem is whatever starts it: a service, a cron job, or a supervisor. Fix that, not the symptom.
This order matters. Jumping straight to SIGKILL destroys the evidence — logs, core dumps, and the process's own error output — that would have told you why it misbehaved.
Frequently asked questions
What is the difference between a process and a thread?
A process has its own memory space; threads share the memory of their process. That is why killing a process kills all its threads, and why a crash in one thread can take the whole process down.
Why does kill sometimes not kill a process?
Three usual reasons: the process is in uninterruptible sleep (D state) waiting on I/O, you are sending SIGTERM to a process that catches and ignores it, or you lack permission — you can only signal your own processes unless you are root.
Is it safe to kill PID 1?
No. PID 1 is the init system, and the kernel protects it from signals that would stop it. Leave it alone.
What is the difference between load average and CPU usage?
CPU usage is a percentage of cores busy right now. Load average is the length of the queue of processes wanting CPU or I/O over 1, 5, and 15 minutes. A high load with low CPU usage usually means I/O, not computation, is the bottleneck.
Should I use kill -9 as my first move?
No. Try SIGTERM first, give the process a few seconds to clean up, and use SIGKILL only when it does not respond. SIGKILL skips cleanup, which can leave files and locks in a bad state.
Limitations
Process tools show you what is happening, not why. top can tell you a process is using CPU, but not which line of code is looping — that needs a profiler or debugger. Signals are coarse: you can stop, pause, or resume a process, but you cannot inspect its internals through signals alone. Permissions also bound you: on shared lab machines you can only manage your own processes, and system services need administrator access. Finally, these commands behave slightly differently across distributions — htop may not be installed, and container environments report host-wide numbers in some tools, so check whether you are inside a container before trusting a host-level reading.
Learned in this order — see, understand, signal politely, escalate only when needed — process management stops being guesswork and becomes the fastest way to get a misbehaving machine back under control.