Processes, Jobs and Services
See what is running with ps and top, stop programs with kill and signals, run jobs in the background, and manage services with systemctl.
Welcome back!
Step 1 of 13Learn
The server is slow
At 2 p.m. users complain that the internal web app is crawling. Andre connects to the server and, within a minute, finds a forgotten data export that has been eating 100% of a CPU core since the morning. He stops it, and the app recovers. Everything he did used four commands from this lesson.
Every running program is a process. Each process has a process ID (PID), an owner, a parent process that started it, and a share of CPU and memory.
psshows processes started from your current terminal.ps auxshows every process on the system: the owner (USER), PID, CPU and memory percentages, and the full command line. Pipe it to grep to find something:ps aux | grep python.topshows a live, updating view sorted by CPU use. PressMto sort by memory,kto kill a process by PID, andqto quit.htopis a friendlier, colorful version you may need to install.pgrep -l nginxprints PIDs of processes by name.
The top of top shows the load average: three numbers for the last 1, 5 and 15 minutes. Roughly, it is the average number of processes running or waiting to run. On a machine with 4 CPU cores, a load of 4 means fully busy; a sustained load of 12 means work is piling up. nproc tells you how many cores you have.
Step 2 of 13Practice · Diagram
Load average on a 4-core server
Compare the load to the number of cores (nproc). Tap a marker.
Which marker means the server is fully busy but not yet queueing work?
Tap the shape that answers the question, then press Check.
- Load 1
About one core busy; three idle.
- Load 4
Every core busy, nothing waiting.
- Load 12
Three times the cores: processes queue and users notice.
Step 3 of 13Practice · Work it out
A server has 8 CPU cores. top shows load averages of 15.2, 14.8, 13.9. Roughly how many times its core count is the 1-minute load? Round to one decimal place.
Step 4 of 13Learn
Stopping processes with signals
You stop a process by sending it a signal, a small numbered message from the kernel. The command is confusingly named kill, though most signals are polite requests.
| Signal | Number | Meaning |
|---|---|---|
| SIGTERM | 15 | "Please shut down." The default for kill. The program can save work and clean up. |
| SIGKILL | 9 | "Stop now." The kernel ends the process immediately; it cannot be caught or ignored. |
| SIGINT | 2 | Interrupt, what Ctrl+C sends to the foreground program. |
| SIGHUP | 1 | Hang up; many services reload their configuration when they receive it. |
$ kill 4821 # sends SIGTERM to PID 4821
$ kill -9 4821 # sends SIGKILL
$ pkill -f export.py # by name or command lineThe right order is TERM first, KILL only if needed. SIGTERM gives a database the chance to finish writing and close its files. SIGKILL can leave half-written files, stale lock files or corrupted data behind. Wait a few seconds after kill, check with ps, and escalate to kill -9 only if the process is truly stuck.
You can signal your own processes freely. Signaling processes owned by other users requires sudo.
Step 5 of 13Practice · Put in order
A runaway process (PID 7310) is hogging the CPU. Put a careful response in order.
Drag the items, or use the arrow buttons, to put them in order.
- Check what it is with ps -p 7310 -f
- Wait a few seconds and check whether it has exited
- Only if it is still running, send SIGKILL with kill -9 7310
- Send it SIGTERM with kill 7310
- Run top to identify the process using the most CPU
Step 6 of 13Compare
SIGTERM vs SIGKILL
| Aspect | SIGTERM (15) | SIGKILL (9) |
|---|---|---|
| Sent by | kill PID (the default) | kill -9 PID |
| Can the program react? | Yes: save, clean up, exit | No: the kernel ends it at once |
| Risk | Low | Half-written files, stale locks |
| Use | First, always | Only if TERM did not work |
Step 7 of 13Learn
Foreground, background and jobs
When you run a command, it normally runs in the foreground: your prompt doesn't come back until it finishes. For long tasks, the shell's job control lets you keep working.
- Add
&at the end to start a command in the background:./export.sh &. The shell prints a job number and PID and gives you the prompt back. - Press Ctrl+Z to pause (suspend) the foreground command.
jobslists the jobs belonging to this shell.bgresumes a paused job in the background;fgbrings a job back to the foreground (fg %2for job number 2).
One catch: background jobs normally die when you close the terminal or your SSH connection drops, because the shell sends them SIGHUP. For long-running tasks on a remote server, start them with nohup command &, which ignores the hang-up signal and writes output to nohup.out, or run them inside a terminal multiplexer like tmux or screen, which keeps a session alive on the server so you can reconnect later.
A common workflow: you start a big copy, realize it will take an hour, press Ctrl+Z, type bg, and carry on working while it finishes.
Step 8 of 13Practice · Match the pairs
Match each action to the command or key that does it.
Tap an answer, then tap the place where it belongs (or drag it there).
- Start a script in the background
- Pause the current foreground program
- Resume a paused job in the background
- Bring a background job to the foreground
- List this shell's jobs
Step 9 of 13Diagram
Moving a job around
Tap a shape with to see more.
- Running in foreground
You wait for the prompt.
- Ctrl+Z: paused
The job is suspended, the prompt comes back.
- bg: running in background
It keeps working while you type other commands.
- fg: back to the front
fg %2picks job number 2 fromjobs.
Step 10 of 13Learn
Services and systemd
Web servers, databases and SSH aren't started by hand. They are services (also called daemons): background processes that start at boot and run without a terminal. On almost every modern distribution they are managed by systemd, controlled with systemctl:
$ systemctl status nginx # is it running? recent log lines
$ sudo systemctl restart nginx # stop and start
$ sudo systemctl reload nginx # re-read config without dropping connections
$ sudo systemctl enable nginx # start automatically at boot
$ sudo systemctl disable nginx # don't start at bootstart and stop affect the service right now; enable and disable affect what happens at the next boot. A service can be running but disabled (it will be gone after a reboot) or enabled but stopped. sudo systemctl enable --now nginx does both at once.
When a service fails, read its logs with journalctl -u nginx. Add -f to follow new entries live, like tail -f, or --since "10 min ago" to narrow the window. A good troubleshooting loop is: edit the config, check it if the program offers a test (nginx -t), restart, then look at systemctl status and the journal.
Step 11 of 13Practice · Diagram
Running now vs starting at boot
start/stop act on the present; enable/disable act on the next boot. Tap a box.
Where does sudo systemctl enable --now nginx put the service?
Tap the shape that answers the question, then press Check.
- Enabled but stopped
Down now, comes up after a reboot.
- Enabled and running
The normal state for a production service.
- Disabled and stopped
Off now and after reboot.
- Running but disabled
Works today, gone after the next reboot.
Step 12 of 13Note
Step 13 of 13Practice · What would you do?
What would you do?
After a reboot, your company's web server isn't serving pages. systemctl status nginx says inactive (dead) and disabled. Yesterday you started it with sudo systemctl start nginx and it worked. What happened and what is the fix?
Lesson complete!