Monitor Linux Processes with ps, top and htop
Monitor Linux processes with ps, top and htop: key options, column meanings, process states, kill and renice, and a five-minute routine for slow servers.
To monitor active processes in Linux, use ps for a one-time snapshot you can filter and script, top for a live view that refreshes every few seconds, and htop for an interactive, colour-coded view with tree mode and mouse support. All three read the same data from /proc, so they differ in presentation and interaction rather than accuracy.
This guide is part of our Linux and RHEL learning track, which starts with setting up RHEL 10 for the first time. It walks through the options you will actually use in each tool, how to read the columns, and a short troubleshooting routine for a busy server. Every command was checked against the procps-ng and htop manual pages.
Key takeaways
- ps prints a static list. Combine it with
-eoand--sortto build exactly the report you need, which makes it the right tool for scripts and cron jobs. - top ships with almost every distribution through the procps-ng package. Single keys inside it sort, filter, renice and kill processes.
- htop is usually an extra package (on RHEL it comes from EPEL). It adds scrolling, tree view, search and function-key menus.
- Load average counts tasks that are running or waiting, including tasks stuck in uninterruptible I/O (state D), so a high load does not always mean CPU is the bottleneck.
- Always try SIGTERM (15) before SIGKILL (9), and prefer
systemctlfor processes that belong to a service.
ps vs top vs htop at a glance
| Feature | ps | top | htop |
|---|---|---|---|
| Output | One snapshot, then exits | Live, refreshes (default 3 seconds) | Live, refreshes, scrollable |
| Installed by default | Yes (procps-ng) | Yes (procps-ng) | Usually not; install the htop package |
| Best for | Scripts, filtering, exact columns | Quick checks on any server | Interactive investigation |
| Kill or renice | No (use kill, renice) | Yes, keys k and r | Yes, F9 and F7/F8 |
| Process tree | ps -ef --forest or ps axjf | Key V (forest view) | F5 |
| Batch output | Native | top -b -n 1 | Not designed for it |
What a process is, in the terms these tools use
Every running program is a process with a process ID (PID) and a parent process ID (PPID). On a systemd distribution, PID 1 is systemd, and everything else descends from it. The kernel exposes each process as a directory under /proc/<PID>, and ps, top and htop all read those files. If you open /proc/1/status you will see the same state, memory and thread figures the tools display.
Each process has a state code. You will see these in the STAT or S column:
| Code | Meaning | What to think when you see many |
|---|---|---|
| R | Running or runnable | CPU demand is high |
| S | Interruptible sleep (waiting for an event) | Normal; most processes sit here |
| D | Uninterruptible sleep, usually disk or network I/O | Storage or NFS may be slow |
| Z | Zombie: exited, but the parent has not collected its status | A parent process is not reaping children |
| T | Stopped by a signal or a debugger | Someone pressed Ctrl+Z or attached a tracer |
| I | Idle kernel thread | Normal |
Using ps for snapshots
ps accepts two option styles. BSD style has no dash (ps aux) and UNIX style uses a dash (ps -ef). Both list every process; they just choose different default columns.
# Every process, BSD style: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
ps aux
# Every process, UNIX style: UID PID PPID C STIME TTY TIME CMD
ps -ef
# Processes owned by one user
ps -u nginx
# A single PID with chosen columns
ps -o pid,ppid,user,stat,etime,cmd -p 1234
Build your own report with -eo and --sort
The most useful ps habit is choosing columns and sorting. This command lists the ten processes using the most CPU:
ps -eo pid,ppid,user,%cpu,%mem,stat,etime,comm --sort=-%cpu | head -n 11
Swap --sort=-%cpu for --sort=-%mem or --sort=-rss to rank by memory. The minus sign means descending. Note that ps %CPU is the average over the life of the process, not the last few seconds. For current CPU use, look at top.
Find processes by name
Avoid ps aux | grep name, because it also matches the grep command itself. pgrep is cleaner:
# PIDs and names of matching processes
pgrep -l sshd
# Match against the full command line, show it
pgrep -af "java -jar"
# Count zombie processes
ps -eo stat | grep -c '^Z'
See the process tree
ps -ef --forest
# or the pstree command from the psmisc package
pstree -p
A tree shows which parent spawned a runaway child. With zombies, the fix is almost always the parent: restart or fix the parent so it reaps its children. You cannot kill a zombie directly because it has already exited.
Using top for a live view
Run top and the screen splits into a summary area and a task list. The first line shows uptime, logged-in users and the load average for the last 1, 5 and 15 minutes. The CPU line breaks time into categories:
| Field | Meaning |
|---|---|
| us | User space processes |
| sy | Kernel |
| ni | Niced (lower priority) user processes |
| id | Idle |
| wa | Waiting for I/O |
| hi / si | Hardware and software interrupts |
| st | Stolen by the hypervisor (virtual machines) |
A high wa points at storage. A high st on a cloud VM means the host is short of CPU, and resizing or moving the instance may help more than tuning the application.
Keys worth memorising
| Key | Action |
|---|---|
| P | Sort by CPU |
| M | Sort by memory |
| T | Sort by cumulative CPU time |
| 1 | Toggle per-CPU lines |
| c | Show full command line |
| u | Filter by user |
| o | Add a filter such as COMMAND=java |
| H | Show threads instead of processes |
| V | Forest (tree) view |
| k | Send a signal to a PID |
| r | Renice a PID |
| d | Change refresh delay |
| W | Save current layout to the config file |
| q | Quit |
Command-line options
# Watch specific PIDs only
top -p 1234,5678
# Only one user's processes
top -u postgres
# Refresh every second
top -d 1
# Batch mode: one iteration, text output for logs or scripts
top -b -n 1 | head -n 20
Batch mode is handy in an incident: run top -b -n 3 -d 5 > /tmp/top.txt and attach the file to the ticket so others can see what the machine looked like.
Using htop for interactive work
htop is a separate project. Install it with your package manager:
# Ubuntu / Debian
sudo apt install htop
# RHEL, Rocky, AlmaLinux (htop is in EPEL)
sudo dnf install epel-release # on RHEL, follow the EPEL instructions for your version
sudo dnf install htop
On RHEL itself, enabling EPEL needs the CodeReady Builder repository and the EPEL release package for your major version. Our guide on configuring RHEL 10 repositories covers that step.
Function keys
| Key | Action |
|---|---|
| F1 | Help |
| F2 | Setup: meters, columns, colours |
| F3 | Search by name (jumps to matches) |
| F4 | Filter (hides non-matches) |
| F5 | Tree view |
| F6 | Choose sort column |
| F7 / F8 | Raise or lower priority (nice) |
| F9 | Send a signal |
| Space | Tag a process (act on several at once) |
| F10 | Quit |
The meters at the top show each CPU core, memory and swap as coloured bars. In the memory bar, green is memory used by processes, while blue and yellow portions are buffers and cache that the kernel can reclaim. That is why a server can look "full" in a naive reading and still be healthy.
Reading memory columns correctly
| Column | Meaning |
|---|---|
| VSZ / VIRT | Virtual address space reserved. Often large and rarely a concern by itself. |
| RSS / RES | Resident memory actually in RAM, including shared pages. |
| SHR | Shared memory (libraries, shared segments). |
| %MEM | RSS as a share of physical RAM. |
Because shared pages count toward each process's RSS, adding the RSS of every process overstates real use. Use free -h and the available column to judge whether the box is short of memory.
Controlling processes after you find them
Signals
# Ask politely (SIGTERM, 15); the process can clean up
kill 1234
# Reload configuration for daemons that support it (SIGHUP, 1)
kill -HUP 1234
# Force stop (SIGKILL, 9); no cleanup, last resort
kill -9 1234
# By name
pkill -f "python worker.py"
If the process belongs to a systemd service, use systemctl restart name instead, otherwise systemd may simply start it again. Our post on managing services and processes in RHEL 10 covers that workflow.
Priority with nice and renice
Nice values run from -20 (highest priority) to 19 (lowest). Regular users can only lower priority; root can raise it.
# Start a backup at low priority
nice -n 10 tar czf /backup/home.tgz /home
# Lower the priority of a running PID
renice -n 15 -p 1234
A five-minute routine for a slow server
- Run
uptimeand compare the load average with the CPU count fromnproc. A load well above the core count for 5 and 15 minutes means sustained pressure. - Open
top, press 1, and read us, sy, wa and st. This tells you whether the pressure is CPU, kernel, I/O or the hypervisor. - Press P, then M, to find the top consumers. Note their PIDs and commands (press c for full commands).
- If wa is high, look for processes in state D:
ps -eo pid,stat,comm | awk '$2 ~ /D/'. Then check disks withiostat -x 1from the sysstat package. - Check memory with
free -hand look for OOM killer messages withjournalctl -k | grep -i oom. - Save evidence with
top -b -n 1andps aux --sort=-%cpu | headbefore you restart anything.
For deeper tools such as vmstat, iostat, sar and perf, see our guide to the best tools for troubleshooting Linux performance.
Automating checks with ps
Because ps output is stable, it is easy to use in a small script. This example warns when any process uses more than 80 percent of a CPU on average:
#!/usr/bin/env bash
set -euo pipefail
threshold=80
ps -eo pid,%cpu,comm --no-headers | while read -r pid cpu comm; do
if awk -v c="$cpu" -v t="$threshold" 'BEGIN{exit !(c>t)}'; then
echo "$(date -Is) high CPU: pid=$pid cpu=$cpu cmd=$comm"
fi
done
A script like this is fine for a lab or a single server. For fleets, run an agent such as Prometheus node_exporter and alert on metrics rather than parsing ps on every host. Text tools like awk are covered in our grep, awk and sed guide.
Containers and cgroups
Processes inside containers are still ordinary Linux processes, so they show up in ps and top on the host. To see resource use grouped by systemd unit or container cgroup, run systemd-cgtop. For a single container, podman top <container> or docker top <container> lists only its processes.
Frequently asked questions
What is the difference between ps, top and htop?
ps prints a one-time snapshot and exits, which suits scripts. top shows a live, refreshing list and is installed almost everywhere. htop is an interactive alternative to top with scrolling, colour meters, tree view and function-key menus, but it usually needs to be installed.
How do I see the processes using the most CPU?
Run ps -eo pid,user,%cpu,comm --sort=-%cpu | head for a snapshot, or open top and press P. Remember that ps shows average CPU over the life of the process, while top shows recent use.
Is htop installed by default on RHEL?
No. On RHEL and its rebuilds, htop comes from the EPEL repository, so you enable EPEL first and then run dnf install htop. On Ubuntu it is in the standard repositories.
What does a high load average mean?
It means many tasks were running or waiting. Linux counts tasks in uninterruptible I/O wait as well as runnable tasks, so compare load with your CPU count and check the wa value in top before blaming CPU.
How do I remove zombie processes?
A zombie has already exited, so killing it does nothing. Find its parent with ps -o ppid= -p <PID> and restart or fix that parent so it collects the exit status.
Should I use kill -9?
Only as a last resort. Send SIGTERM first so the process can close files and connections. If it belongs to a systemd service, use systemctl to stop or restart it.
How do I save top output to a file?
Use batch mode: top -b -n 1 > top.txt for one snapshot, or add -n 5 -d 2 to capture five snapshots two seconds apart.
Learn Linux administration hands-on
Process monitoring is a core skill in our Linux administration training, offered as classroom sessions in Kharadi, Pune and live online across India. For more command practice, see 20 Linux commands for DevOps engineers.
References
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0