
When a Linux server feels slow, a program hangs, or something is eating memory, you are really asking questions about processes: what is running, who started it, how much of the machine it uses, and how to stop it cleanly. This guide explains what a process is, how to list and sort them with ps and top, how signals and kill work (and why kill -9 should be your last resort), how to change priority with nice, and how to run long jobs in the background. Examples work on RHEL, AlmaLinux, Rocky Linux, Debian and Ubuntu.
What a process is
A process is a running program. Each one has:
- a PID, its process ID, and a PPID, the ID of the process that started it (its parent);
- an owner, the user it runs as, which decides what it may access;
- a state, such as running or sleeping;
- CPU and memory use, and a list of open files and network connections.
Every process comes from a parent. The first one, systemd (PID 1), starts the rest. Run pstree to see the family tree.
Listing processes with ps
ps takes a snapshot. Two forms cover nearly every need:
ps aux # every process, with user, CPU and memory
ps -ef # every process, with PID and parent PID
$ ps aux | head -4
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.3 172100 15200 ? Ss Nov16 0:03 /usr/lib/systemd/systemd
root 812 0.0 0.1 15800 9020 ? Ss Nov16 0:00 sshd: /usr/sbin/sshd -D
nginx 1204 0.1 0.5 22400 11800 ? S Nov16 0:42 nginx: worker process
For a custom view, choose the columns and the sort order yourself. This one shows the ten biggest CPU users:
ps -eo pid,ppid,user,%cpu,%mem,etime,cmd --sort=-%cpu | head -11
ps -eo pid,user,%mem,rss,cmd --sort=-%mem | head -6 # biggest memory users
A minus in --sort=-%cpu means “highest first”. RSS is the memory a process really holds in RAM, in kilobytes, and etime is how long it has been running.
Finding one process
pgrep -a nginx # PIDs and command lines that match a name
pidof sshd # PIDs of a program
ps -p 1204 -o pid,user,etime,cmd # details for one PID
Avoid ps aux | grep name in scripts: it also matches the grep itself. pgrep does not.
What the STAT letters mean
| State | Meaning | Worth worrying about? |
|---|---|---|
R |
Running or ready to run | Normal. Many of them on a busy system means high load |
S |
Sleeping, waiting for something | Normal, most processes are here |
D |
Uninterruptible sleep, usually waiting for disk or network storage | Several in D for a long time points to a storage problem. kill cannot stop them |
T |
Stopped (paused), for example with Ctrl+Z | Resume it or end it |
Z |
Zombie: finished, but the parent has not collected its exit status | Harmless in small numbers. You cannot kill a zombie, you deal with its parent |
Extra letters after the state add detail: s is a session leader, l is multi-threaded and + is in the foreground.
Watching live with top
top refreshes every few seconds. The summary at the top tells you the story before you read a single process:
top - 10:15:02 up 12 days, 3:41, 2 users, load average: 0.42, 0.55, 0.60
Tasks: 142 total, 1 running, 141 sleeping, 0 stopped, 0 zombie
%Cpu(s): 3.1 us, 1.0 sy, 0.0 ni, 95.6 id, 0.2 wa, 0.0 hi, 0.1 si
MiB Mem : 3900.5 total, 410.2 free, 1620.8 used, 1869.5 buff/cache
MiB Swap: 2048.0 total, 2040.0 free, 8.0 used. 1950.3 avail Mem
- Load average shows the average number of processes that want the CPU, over 1, 5 and 15 minutes. Compare it with the number of CPU cores (
nproc). On a 4-core machine, a load of 4 means fully busy and 12 means a long queue. - %Cpu(s):
usis your programs,sythe kernel,ididle, andwais time spent waiting for disk. A highwameans storage is the bottleneck, not the CPU. - Memory: look at
avail Mem, notfree. Linux uses spare RAM for caching, and that cache is given back when programs need it.
Keys inside top:
| Key | Action |
|---|---|
P / M |
Sort by CPU / by memory |
1 |
Show each CPU core separately |
c |
Show the full command line |
u |
Filter by user |
k |
Kill a process (asks for a PID and a signal) |
q |
Quit |
For a friendlier view, install htop (on RHEL-family systems it comes from EPEL: sudo dnf install htop). Also useful: uptime for the load average, and free -h for memory.
Stopping processes: signals and kill
kill does not just “kill”. It sends a signal, a short message to the process. The process can react to most signals, which is how programs shut down cleanly.
| Signal | Number | Meaning |
|---|---|---|
SIGTERM |
15 | “Please stop.” The program can save its work and exit. This is the default |
SIGINT |
2 | Interrupt, what Ctrl+C sends |
SIGHUP |
1 | Hang up. Many services reload their configuration on it |
SIGKILL |
9 | The kernel ends the process at once. The program gets no chance to clean up |
SIGSTOP / SIGCONT |
19 / 18 | Pause and resume (SIGSTOP cannot be caught) |
kill 1204 # polite request (SIGTERM)
kill -HUP 1204 # ask a service to reload its configuration
kill -9 1204 # last resort
pkill nginx # signal processes by name
pkill -f 'python3 report.py' # match against the whole command line
killall httpd # signal every process with that exact name
The right order: send SIGTERM first, wait a few seconds, check with ps -p PID, and only then use kill -9. A process killed with -9 can leave temporary files, locks and half-written data behind.
You can only signal your own processes. Use sudo for those of other users. If the process is a service, prefer sudo systemctl restart name so that systemd stays in charge. See systemd basics. Be careful with pkill and killall: check the match first with pgrep -a.
Zombies and stuck D processes. A zombie is already dead, so kill does nothing; find its parent with ps -o ppid= -p PID and restart or fix the parent. A process stuck in D is waiting on I/O and ignores signals until the storage answers or the machine is rebooted.
Priority with nice and renice
The nice value tells the scheduler how willing a process is to give way. It ranges from -20 (most priority) to 19 (least). The default is 0, and only root can lower the value.
nice -n 10 tar czf backup.tgz /srv/data # start a job at low priority
sudo renice -n 5 -p 4310 # change a running process
ionice -c3 tar czf backup.tgz /srv/data # idle disk priority too (only uses idle I/O time)
Use nice for heavy background work such as backups and compression, so interactive programs stay responsive.
Foreground, background and long-running jobs
command & # start in the background
jobs # list this shell's background jobs
fg %1 # bring job 1 to the foreground
bg %1 # let a stopped job continue in the background
Ctrl+Z # pause the foreground job
Ctrl+C # interrupt it
Background jobs started from a shell normally die when you close the terminal or the SSH session drops. Three ways to keep one alive:
nohup command &ignores the hangup signal and writes output tonohup.out.disowndetaches an already-running job from the shell.tmux(orscreen) gives you a session you can leave and rejoin later, the best choice for interactive long work over SSH.
Anything that must run permanently, restart after a crash and start at boot does not belong in nohup. Make it a systemd service.
Looking inside a process
ls -l /proc/1204/fd | head # files and sockets the process has open
cat /proc/1204/status | head -12 # name, state, memory, threads
sudo lsof -p 1204 | head # open files with more detail
sudo lsof -i :80 # who uses port 80?
sudo fuser -v /var/log/messages # who has this file open?
Every process has a folder named after its PID in /proc. It is the source that ps and top read from, and it is handy when those tools are not installed. Port questions are covered in Linux networking commands.
When memory runs out
If the machine runs out of memory, the kernel’s OOM killer ends a process to save the system, usually the one using the most memory. Signs: a service that stops without any message of its own. Check the kernel log:
sudo journalctl -k | grep -i -E 'out of memory|oom'
free -h
ps -eo pid,user,%mem,rss,cmd --sort=-%mem | head -6
The fix is not to kill more things: find the process that grows, limit it (systemd can set MemoryMax=), fix the leak, or add memory.
Troubleshooting guide
| Problem | First command | What to look for |
|---|---|---|
| Server is slow | uptime then top |
Load higher than the core count; high wa means disk, high us means a busy program |
| One process uses 100% CPU | ps -eo pid,user,%cpu,cmd --sort=-%cpu | head |
Is it expected? If not, kill PID, then find the cause in its logs |
| Memory is nearly full | free -h, ps ... --sort=-%mem |
Low available memory, swap in use, OOM messages in the log |
| A command hangs | ps -o pid,stat,wchan,cmd -p PID |
State D points to storage; S means it is waiting for something |
| Port already in use | sudo ss -ltnp 'sport = :PORT' |
The program that owns the port |
| Many zombies | ps -eo stat,ppid | grep Z |
The common parent; restart that program |
Disk problems show up here too. If the load is high because of waiting on storage, continue with finding what uses disk space. For the commands used around these tasks, keep the Linux commands cheat sheet close.
Quick reference
| Task | Command |
|---|---|
| List all processes | ps aux |
| Top CPU users | ps -eo pid,user,%cpu,cmd --sort=-%cpu | head |
| Find a process by name | pgrep -a name |
| Live view | top (or htop) |
| Stop politely | kill PID |
| Force stop | kill -9 PID (last resort) |
| Lower priority | renice -n 10 -p PID |
| Keep a job alive after logout | nohup command & or tmux |
Frequently asked questions
What is the difference between kill and kill -9?
kill sends SIGTERM, a request the program can handle by saving its work and exiting. kill -9 sends SIGKILL, which the kernel carries out immediately with no clean-up. Use the plain version first.
How do I find which process is using a port?
Run sudo ss -ltnp 'sport = :80' (replace 80 with your port) or sudo lsof -i :80. Both show the program and PID that hold the port.
Why can’t I kill a zombie process?
A zombie has already finished. It only remains in the process table until its parent reads the exit status. Restart or fix the parent process and the zombie disappears.
What does load average mean?
It is the average number of processes running or waiting to run over the last 1, 5 and 15 minutes. Compare it with your number of CPU cores. Load equal to the core count is fully busy, and much higher means work is queueing.
How do I keep a command running after I close SSH?
Start it inside tmux or screen so you can reattach later, or use nohup command &. For anything permanent, create a systemd service instead.
More tutorials like this
Linux Permission Denied Error: Causes and How to Fix It (chmod, namei, id)
Fix the Linux Permission denied error: read ls -l, namei -l and id, then add only the permission letter you need with chmod. Real…
Why Is My Website Slow? Measure DNS, TLS and Server Time with curl
Use curl to split a web request into DNS, connection, TLS, server and download time, read the numbers correctly and fix the slow part.
Why Did My Windows PC Restart or Crash? Find the Answer in Event Viewer and PowerShell
Find out why Windows restarted: the key event IDs (41, 6008, 1074, 1001), PowerShell commands to read them, and what to fix for each…


