Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

List Every Process with ps aux

ps aux

This prints one line per process. The columns you will use most:

ColumnMeaning
USERAccount that runs the process.
PIDProcess ID, used by kill.
%CPU, %MEMShare of CPU and memory.
RSSPhysical memory in use, in KiB.
STATState: R running, S sleeping, D waiting for disk, Z zombie.
COMMANDThe program and its arguments.

The list is long. Page through it with ps aux | less.

ps -ef: the Other Format

ps -ef

This shows the same processes in a different layout. Its useful extra column is PPID, the parent process ID, which tells you which process started which. Both forms work on every distribution; choose the one you find easier to read.

Sort by CPU or Memory

ps aux --sort=-%cpu | head -n 10
ps aux --sort=-%mem | head -n 10

The minus sign sorts from high to low. To choose your own columns, use -o:

ps -eo pid,user,%cpu,%mem,etime,cmd --sort=-%mem | head -n 15

etime is how long the process has been running. Note that %CPU in ps is an average over the process lifetime; for current use, use top.

Find a Process by Name or User

pgrep -a nginx
pgrep -u deploy -a
pidof nginx
ps -fu deploy

pgrep -a prints the PID and full command of every match, and -u limits it to one user. If you prefer grep, write the first letter in brackets so grep does not list itself: ps aux | grep '[n]ginx'.

Show the Process Tree

pstree -p
ps -ef --forest

A tree shows, for example, the nginx master with its workers, or which shell started a stray script. pstree is part of the psmisc package; on minimal images install it with sudo apt install psmisc on Debian and Ubuntu or sudo dnf install psmisc on AlmaLinux and Rocky Linux.

Watch Processes Live with top and htop

top is installed everywhere. Useful keys while it runs:

  • P and M: sort by CPU or by memory.
  • 1: show each CPU core.
  • u: show one user only.
  • q: quit.

htop is easier to read and lets you scroll and search. Install it with sudo apt install htop on Debian and Ubuntu; on AlmaLinux and Rocky Linux it comes from EPEL: sudo dnf install epel-release, then sudo dnf install htop. For disk and network use per process, and for history, see how to use atop.

Stop a Process Safely

kill 12345
pkill -f backup.sh

kill sends SIGTERM, which asks the program to finish and clean up. Wait a few seconds and check with ps -p 12345. Use kill -9 only when a process ignores SIGTERM, because it gives no chance to save data. If the process belongs to a service, stop it with sudo systemctl stop name instead; otherwise systemd may start it again. See how to list services with systemctl.

Zombies and Processes Stuck on Disk

  • Z (zombie): the process has ended, but its parent has not collected the exit status. It uses no CPU or memory. Restarting the parent clears it; kill does not.
  • D (uninterruptible): the process waits for disk or network storage and cannot be killed until that returns. Many D processes point at a storage problem.

To find which process holds a port or a file, read the lsof command. Jobs you started with nohup appear in these lists like any other process.

Was this answer helpful?
Loading...