Skip to content

The ps command

The ps command lists running processes…

The ps command lists running processes; ps aux shows every process on the machine with its owner, PID, CPU and memory use.

Taught in Intermediate, lesson 26; more in Ninja

A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.

Usage

ps
ps aux
ps -ef
ps -u USER
ps -p PID
ps -o COLUMNS [--sort=COLUMN]

List running processes. Shows the processes running on this machine. On its own, ps lists the ones in your terminal; ps aux and ps -ef list every process, with its owner, process ID (PID), CPU and memory use, and the command that started it. ps aux | grep NAME finds one, and the grep shows up in the list itself, because it is running too. The processes here are pretend: a few system programs, services such as nginx on web, and whatever you start.

In the practice terminal:The processes are pretend ones on the practice machine: a few system programs, your shell, and anything you start.

How to use ps

List every process: ps aux

a and x take in every user’s processes and those with no terminal; u adds the owner, CPU and memory columns. The PID column is the number other commands, such as kill, need.

ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.3  42830 12900 ?        Ss   Jan09   0:53 /sbin/init splash
root         302  0.0  0.4  52280 16400 ?        S    Jan09   0:53 /usr/lib/systemd/systemd-journald
root         611  0.0  0.1  15290  2700 ?        Ss   Jan09   0:53 /usr/sbin/cron -f -P
learner     4242  0.0  0.1  22040  5200 pts/0    Ss   09:00   0:00 -bash
learner     5000  0.0  0.1   9000  3400 pts/0    R+   09:01   0:00 ps aux

The full format: ps -ef

The same list in the other common style, with each process’s parent (PPID). Add --forest to see which process started which.

ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 Jan09 ?        00:00:53 /sbin/init splash
root         302       1  0 Jan09 ?        00:00:53 /usr/lib/systemd/systemd-journald
root         611       1  0 Jan09 ?        00:00:53 /usr/sbin/cron -f -P
learner     4242    4200  0 09:00 pts/0    00:00:00 -bash
learner     5000    4242  0 09:01 pts/0    00:00:00 ps -ef
ps -ef --forest
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 Jan09 ?        00:00:53 /sbin/init splash
root         302       1  0 Jan09 ?        00:00:53  \_ /usr/lib/systemd/systemd-journald
root         611       1  0 Jan09 ?        00:00:53  \_ /usr/sbin/cron -f -P
learner     4242    4200  0 09:00 pts/0    00:00:00 -bash
learner     5000    4242  0 09:01 pts/0    00:00:00  \_ ps -ef --forest

Find one process: ps aux | grep

grep finds itself too, because its own command line has the word in it. pgrep prints just the PIDs.

ps aux | grep cron
root         611  0.0  0.1  15290  2700 ?        Ss   Jan09   0:53 /usr/sbin/cron -f -P
learner     5001  0.0  0.1   9000  3400 pts/0    S+   09:01   0:00 grep cron
pgrep cron
611

Only your processes: ps and ps -u

With no options, ps lists only the processes in this terminal.

ps
    PID TTY          TIME CMD
   4242 pts/0    00:00:00 bash
   5000 pts/0    00:00:00 ps
ps -u learner
    PID TTY          TIME CMD
   4242 pts/0    00:00:00 bash
   5000 pts/0    00:00:00 ps

Choose the columns and sort: ps -o, --sort

-o names the columns; --sort=-%cpu puts the busiest first (the minus means largest first).

ps -o pid,user,%cpu,cmd --sort=-%cpu
    PID USER     %CPU CMD
   4242 learner   0.0 -bash
   5000 learner   0.0 ps -o pid,user,%cpu,cmd --sort=-%cpu

See a process you started

A command started with & keeps running in the background and shows up with its own PID.

sleep 600 & ps
[1] 5000
    PID TTY          TIME CMD
   4242 pts/0    00:00:00 bash
   5000 pts/0    00:00:00 sleep
   5001 pts/0    00:00:00 ps

Options

auxevery process, with user, %CPU, %MEM, start time and command
-e, -Aevery process
-ffull format: UID, PID, PPID (parent), start time, command
-u USERonly this user’s processes
-p PIDonly these process IDs
-C NAMEonly processes with this name
-o LISTchoose the columns: pid, ppid, user, %cpu, %mem, stat, etime, comm, cmd
--sort=-%cpusort by a column (- for largest first)
--forestshow parents and children as a tree

More examples

ps -ef | grep cron
Find one process
root         611       1  0 Jan09 ?        00:00:53 /usr/sbin/cron -f -P
learner     5001    4242  0 09:01 pts/0    00:00:00 grep cron

Questions about ps

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

They list the same processes in two styles. ps aux shows CPU and memory use; ps -ef shows the parent process ID. Use whichever has the columns you need.

What does the STAT column in ps mean?

The process state: R running, S sleeping (waiting for something), T stopped, Z a zombie that has ended but not been collected. Extra letters: s marks a session leader and + a process in the foreground of its terminal.

How do I find the PID of a program?

pgrep name prints it, and ps aux | grep name shows the whole line. The PID is the second column of ps aux.

What is the difference between ps and top?

ps prints a snapshot and ends. top keeps running, redrawing the busiest processes every few seconds until you press q.

Learn it step by step

Every everyday command on one page, to print or keep open: the Linux commands cheat sheet.