In one minute
- A process is a program that is running right now. A signal is a short message you send to a process, such as "please stop".
- When a server is slow, a port is "already in use" or a deploy hangs, you are really asking about processes: what is running, who started it, how much it uses, and how to stop it safely.
- Every process gets a number called a PID. You find it with
psortop, then send it a signal withkill. The polite signal lets the program tidy up first. The forceful one stops it at once. - 👉 High CPU or memory, a stuck program, "port already in use", or stopping an app before a deploy.
Think of it like: a kitchen. Each cook is a process with a name badge (PID). You can politely ask a cook to finish the dish and leave (SIGTERM), or a security guard can drag them out mid-dish (SIGKILL).
What a process has
| Property | Meaning |
|---|---|
| PID | Process ID, a unique number |
| PPID | The Parent's PID: which process started it |
| User | Who it runs as (this decides what it is allowed to touch) |
| State | Running, sleeping, stopped or zombie |
| CPU and memory | How much it is using |
| Command | The program and its arguments |
PID 1 is the first process Linux starts (usually systemd). Every other process comes from it, like a family tree.
Listing processes: ps
ps takes a snapshot of the running processes.
👉 "Is my app running?", "Who is using all the memory?"
ps auxps aux | grep nginxUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 812 0.0 0.0 55220 1520 ? Ss Nov25 0:00 nginx: master processwww-data 813 0.0 0.1 55900 5400 ? S Nov25 0:12 nginx: worker processlynuxpro 2211 1.2 3.4 912000 140000 ? Sl 09:01 0:45 java -jar /opt/app/app.jar| Column | Meaning |
|---|---|
%CPU / %MEM | Share of CPU and memory |
VSZ | Memory the process has reserved (often big, usually not a worry) |
RSS | Memory it is really using, in KB. This is the number that matters |
STAT | R running, S sleeping, D waiting on disk, Z zombie, T stopped |
TIME | Total CPU time used so far |
Remember it:
ps aux= "show me all processes, with users, including ones not tied to a terminal (x)".
Useful versions on real servers:
ps -ef --forest # show the parent-child treeps aux --sort=-%mem | head -n 6 # top 5 memory userspgrep -a java # find processes by nameLive view: top and htop
top is a live, updating view of processes, like Task Manager on Windows.
👉 Something is slow right now and you want to watch what is busy.
| Key | What it does |
|---|---|
P | Sort by CPU |
M | Sort by memory |
k | Kill a process (asks for the PID) |
1 | Show each CPU core |
q | Quit |
The top lines show the load average (explained in the performance lesson), memory and swap. htop is a friendlier, colourful version, if it is installed.
Stopping processes: signals and kill
Despite its name, kill does not always kill. It sends a signal. For most signals, the process decides how to react.
Stopping a program the polite way lets it finish requests, save data and close files.
| Signal | Number | Meaning | Can the process ignore it? |
|---|---|---|---|
| SIGTERM | 15 | "Please shut down cleanly" (the default) | Yes, it can tidy up first |
| SIGKILL | 9 | "Stop now", forced by Linux itself | No |
| SIGHUP | 1 | Often "reload your config" | Yes |
| SIGINT | 2 | What Ctrl+C sends | Yes |
| SIGSTOP / SIGCONT | 19 / 18 | Pause / resume | No / yes |
kill 2211kill 2211 # polite: SIGTERM, lets the app finish requests and close fileskill -9 2211 # last resort: SIGKILL, no cleanup at allpkill -f app.jar # signal by name instead of PIDkill -HUP 812 # ask nginx to reload its configAlways try SIGTERM first and wait a few seconds. kill -9 skips all cleanup: temporary files stay behind, connections drop mid-request, and databases may need repair.
Remember it: 15 = please, 9 = now. Ask nicely before you force.
Same rule in Kubernetes: when it stops a pod, it sends SIGTERM, waits (30 seconds by default), then sends SIGKILL. Apps that handle SIGTERM properly can be updated with zero downtime.
Foreground, background and jobs
A foreground program holds your terminal until it finishes. A background program runs while you keep typing.
👉 Running a long task while you do something else in the same terminal.
| Command | What it does |
|---|---|
long-task & | Start it in the background |
| Ctrl+Z | Pause the program in front |
bg / fg | Resume it in the background / bring it back to the front |
jobs | List jobs in this terminal |
nohup cmd & | Keep it running after you log out |
For anything that must really keep running, such as an app, use a systemd service (next lesson), not nohup.
Which process is using this port?
👉 You start an app and get "address already in use".
ss -tulpnNetid State Local Address:Port Processtcp LISTEN 0.0.0.0:22 sshdtcp LISTEN 0.0.0.0:80 nginxtcp LISTEN 127.0.0.1:8080 javaNow you know Java holds port 8080. On servers, sudo lsof -i :8080 gives the same answer.
Zombies and orphans
- A zombie (
Z) has finished, but its parent has not collected its exit result yet. It uses no CPU or memory, only a PID slot. Many zombies mean the parent program is buggy. Fix or restart the parent. - An orphan is a process whose parent died. PID 1 adopts it, so it keeps running normally.
Real-world scenario: a runaway process
CPU is at 100% and the app is slow. You find the cause and stop it politely:
ps auxtopps aux --sort=-%cpu | head -n 3kill 31337sleep 10; ps -p 31337 || echo "stopped cleanly"kill -9 31337 # only if it is still there- Find the biggest CPU user.
- Ask it to stop (SIGTERM).
- Wait, then check whether it is gone.
- Force it only if it is still there.
Then find out why it ran away (logs, a recent deploy), so it does not happen again.
Common mistakes
- Using
kill -9first. It skips cleanup and can damage data. - Killing the wrong PID. Always check first with
ps -p PID -o pid,user,cmd. - Running services with
nohup. They do not restart after a crash or reboot. Use systemd.
Practice
- List all processes and find the nginx master and worker processes.
- Find which process listens on port 8080.
- Send SIGTERM to the Java process (PID 2211) in the practice terminal.
- Explain to a teammate why Kubernetes sends SIGTERM before SIGKILL.
Cheat sheet
| Command | What it does |
|---|---|
ps aux | Every process with CPU and memory |
ps aux --sort=-%cpu | Biggest CPU users first |
top / htop | Live view |
kill PID | Polite stop (SIGTERM) |
kill -9 PID | Forced stop (SIGKILL), last resort |
pkill -f name | Send a signal by name |
ss -tulpn | Which process listens on which port |
Key takeaways
- A process is a running program, and its PID is its number.
ps auxandtopshow what is running.ss -tulpnshows who uses which port.killsends a message to a program. It does not always kill it.- Ask nicely first (
kill, signal 15). Force it (kill -9) only as a last resort. - Apps that must keep running belong in systemd.