ps Command in Linux: List and Find Processes with Examples (ps aux, ps -ef)

ps command in linux - custom-pscmd-featured.png

ps (process status) prints a snapshot of the processes running on a Linux system. Unlike top or htop it does not refresh,
which makes it ideal for scripts, quick checks and piping into grep, sort or awk.

This guide explains the two styles you will see everywhere, ps aux and ps -ef, what each column means, and the handful of options that answer real questions:
is it running? who started it? what is using all the memory?

Quick answer: ps aux lists every process with CPU and memory; ps aux --sort=-%mem | head shows the biggest memory users; pgrep -a nginx finds a process by name.

ps With No Options

Plain ps shows only processes started from your current terminal, which is rarely what you want on a server. Add options to see the whole system.

bashyour shell only
ps
#    PID TTY          TIME CMD
#   2214 pts/0    00:00:00 bash
#   2290 pts/0    00:00:00 ps
Plain ps
Only your terminal’s processes

ps aux: Every Process With CPU and Memory

ps aux (BSD style, no dash) lists all processes for all users with %CPU, %MEM, VSZ (virtual size), RSS (resident memory in KB), STAT (state) and START time.

textexample ps aux output
USER   PID %CPU %MEM    VSZ   RSS TTY  STAT START   TIME COMMAND
root     1  0.0  0.1 168000 11800 ?    Ss   Nov20   0:09 /sbin/init
mysql  912  2.3 18.4 2.1g  1.4g  ?    Ssl  Nov20  41:12 /usr/sbin/mariadbd
www    1503 0.4  1.2 310m  98m   ?    S    09:14   0:21 php-fpm: pool www
ps aux
All processes, resource columns

ps -ef: The System V Style

ps -ef shows the same processes with PPID (parent PID) and full command lines, which is handy for seeing what started a process. Add -F for extra size columns.

bashUNIX style
ps -ef
ps -eF | head
Noteps aux and ps -ef list the same processes. Use aux for resource usage and -ef for parent-child relationships.
ps -ef
Parent PIDs and full commands

Read Process States (STAT)

The STAT column tells you what a process is doing: R running, S sleeping, D uninterruptible sleep (usually waiting on disk or NFS), T stopped, Z zombie. Extra letters add detail, such as s session leader and + foreground.

bashfind processes stuck in D state or zombies
ps -eo pid,stat,cmd | awk '$2 ~ /^D/'
ps -eo pid,ppid,stat,cmd | awk '$3 ~ /^Z/'
TipMany processes in D state usually mean slow or hung storage. Zombies are cleaned up by their parent; see the zombie process check script.
Process states
R, S, D, T, Z

Find a Process by Name

Piping into grep works but also matches the grep command itself. pgrep or ps -C are cleaner.

bashfind nginx
ps aux | grep [n]ginx        # the [n] trick hides the grep line
pgrep -a nginx              # PID and command line
ps -C nginx -o pid,user,%cpu,%mem,cmd
Find a process
grep, pgrep, ps -C

Sort by CPU or Memory

--sort orders the output; a minus sign sorts descending. Combined with head, it is the fastest way to answer what is eating the server.

bashtop 10 by memory and CPU
ps aux --sort=-%mem | head -11
ps aux --sort=-%cpu | head -11
Note%CPU in ps is averaged over the process lifetime, so a spike that just started may look small. Use top for live load.
Top consumers
–sort=-%cpu and -%mem

Show the Process Tree

Tree views show which process started which, for example the worker processes under a web server master or a runaway child of a cron job.

bashtrees
ps -ef --forest | less
ps -o pid,ppid,cmd --ppid 1503   # children of PID 1503
pstree -p | less
Process tree
–forest and pstree

Choose Your Own Columns

-o (or -eo for all processes) prints only the fields you name, which keeps scripts simple. etime shows how long a process has been running.

bashcustom output
ps -eo pid,user,%cpu,%mem,etime,cmd --sort=-%cpu | head
ps -p 912 -o pid,etime,rss,cmd        # one PID
ps -u www-data -o pid,cmd               # one user
TipTo stop a process you have found, see kill, pkill and killall.
Custom columns
-eo with the fields you need

Quick Reference

What does ps aux mean?

a lists processes of all users, u shows user-oriented columns such as %CPU and %MEM, and x includes processes without a terminal, such as daemons.

What is the difference between ps aux and ps -ef?

Both list every process. ps aux (BSD style) shows CPU and memory usage; ps -ef (System V style) shows the parent PID and start time.

How do I find a process by name in Linux?

Use pgrep -a name, or ps aux | grep [n]ame so the grep command itself is not listed.

How do I see which process uses the most memory?

Run ps aux --sort=-%mem | head. The RSS column shows resident memory in kilobytes.

What does a process in D state mean?

D is uninterruptible sleep: the process is waiting on I/O, usually disk or network storage, and cannot be killed until the I/O finishes.

Cheat Sheet

  • ps aux, ps -ef, ps -ef --forest
  • ps aux --sort=-%mem | head, pgrep -a name, ps -eo pid,etime,cmd

Related tutorials

Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.