$_ CLI In Depth
Learning progress 0%
lesson processes signals job-control

Listing Processes: ps, top & /proc

5 min read Module 10: Processes, Signals & Job Control Updated Dec 5, 2026
Cheat Sheet
0:00 / 3:14

ps is a snapshot

The ps program reads the process table once and prints what it found. Its options come in two families. The BSD style has no dash, as in ps aux. The POSIX style uses a dash, as in ps -ef. Both styles work in the lab because the installed ps is from procps-ng, which accepts both. The two families print slightly different default columns, so read the header before you trust a column.

A common starting point is to list every process with a few columns. The head command keeps the output short so that the first lines are easy to read.

BASH1 lines
ps -eo pid,ppid,stat,comm | head -n 6

The -e option selects every process, and -o picks the columns. The first line of output is the header, followed by the processes in PID order. PID 1 comes first, and later lines show the children it created.

Filtering the list

Scanning a long list by eye is slow. The -C option selects processes by command name, and -p selects by PID. The pgrep program from the same package prints only the PIDs that match a name, which is useful in scripts. The args column shows the full command line, which separates two processes that share a name, such as two instances of a shell script.

BASH2 lines
ps -C sleep -o pid,args
pgrep -x bash

If no sleep process is running, the first command prints only its header. The pgrep -x form matches the whole command name exactly, so it does not match a longer name that merely starts with the same letters.

The difference between these tools is mostly about time. Each one gives you a view of one moment, and the only way to see a trend is to repeat the view. A process whose CPU time keeps growing between two snapshots is busy, while one whose CPU time stays flat is idle even though it is running. When you need that comparison, save two snapshots to files and compare them with diff, or let top refresh for a few seconds. A process that appears in one snapshot and not in the next is not necessarily a problem, because short-lived commands come and go all the time.

Showing the tree

The pstree program, from the psmisc package, draws the parent and child relationships as indented text. With -p it adds the PID to each name. Run it on your own shell to see how far up the tree it goes.

BASH1 lines
pstree -p $$

The output starts at the top process of the branch that contains your shell and descends to the shell itself. If you run this from a child of your shell, such as a command substitution, the child is shown indented under the shell. This view is the fastest way to answer the question which program started this one.

top for changing load

The top program refreshes the list every few seconds, and by default it sorts by CPU use. Interactive use needs a full terminal. In the lab you can ask for one batch snapshot with -b and -n 1, and then pipe it to head. The first lines show the load averages, the task counts by state, and the memory summary, followed by the top processes.

BASH1 lines
top -b -n 1 | head -n 12

The task line counts processes by state, using the same letters as the STAT column. The summary is useful when you want to know whether the machine is busy, and the process lines below it tell you which process is busy.

Tip

In an interactive top, press k to kill a process by PID, and q to quit. Be careful with k, because it sends SIGTERM to the process you name, which is a real signal to a real program.

/proc is the source

Every tool above reads the /proc file system. It is not a real disk. The kernel generates each file when you read it. Each process has a directory named after its PID, and the files inside describe it. The cmdline file holds the arguments separated by NUL bytes, and the cwd link points at the current directory. The /proc/self name always refers to the process that reads it.

BASH1 lines
tr "\0" " " < /proc/self/cmdline; echo

The command prints the arguments of the tr process itself, which shows that /proc/self follows the reader. The NUL separators become spaces so the output is readable. Reading /proc directly is useful when no tool is installed, which is the case on some minimal systems, and it is also how you check a value that a tool does not show.

Hands-on: pick the right view

Work through this short sequence. First, count how many processes exist. Then list the processes whose state begins with S, and finally draw the tree from your shell. Each command answers one question, and together they show how the three tools complement each other.

BASH3 lines
ps -e --no-headers | wc -l
ps -eo stat,comm --no-headers | grep -c "^S"
pstree -p $$

The counts change from run to run, so the exact numbers are not the point. Notice that the tree output and the process count come from the same table, and that a state filter uses the letters you learned in the previous unit. Use ps for a snapshot, top to watch change, and /proc when you need one raw value.

Parents, children and process states

Visualizer

Every process has a PID and a parent PID. Follow fork, exec and wait, then see how a zombie and an orphan show up in ps.

1 / 5
ps -eo pid,ppid,stat,comm (illustrative values)
PIDPPIDSTATCOMMAND
41204101Sbash

Every process has a PID and a PPID, the PID of its parent. For example, the interactive shell here is PID 4120. It sleeps (state S) while it waits for your next line.

echo "shell $$"; sh -c 'echo "child $$, parent $PPID"'; echo "shell waited, status $?"
Terminal lab · 3 steps · real Linux in your browser

Snapshot and filter the process list

Take a ps snapshot, filter by command name, and draw the tree from your shell.

01
Take a snapshot with the columns you want
Use ps with -e to select every process and -o to choose the PID and command columns. Save the output in ps.txt. ``bash ps -eo pid,comm > ps.txt `` The first line of ps.txt is the header, and the rest are one line per process.
Show hint for step 1
Use -e to select all processes and -o pid,comm for the columns.
02
Select only the bash PIDs
pgrep prints the PIDs of processes whose name matches. The -x option requires an exact match, so it does not pick up longer names. ``bash pgrep -x bash > bash-pids.txt `` The file should contain only numbers, one per line.
Show hint for step 2
Use pgrep -x bash and redirect the output to bash-pids.txt.
03
Draw the tree from your shell
pstree with -p draws the parent and child processes with their PIDs. Give it the PID of your shell, which is in the special variable $$. ``bash pstree -p $$ > tree.txt `` The first line of tree.txt starts with the name of your shell followed by its PID in parentheses.
Show hint for step 3
Use pstree -p and pass $$ as the process to draw from.
Check yourself Question 1 of 4
Concept Check Selecting every process recall

Which ps option selects every process on the system?

Recap & Key Takeaways

ps takes a snapshot of the process table, and options such as -e, -p, -C, and -o choose processes and columns.
pgrep prints matching PIDs for scripts, and pstree -p draws the parent and child relationships with PIDs.
top -b -n 1 gives a single batch snapshot that can be piped to other commands, and it sorts by CPU use by default.
Every tool reads /proc, where each process has a directory named after its PID that holds files such as status and cmdline.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue