Processes: ps, top and the process tree

Beginner · 20 min

See what is running with ps and top, read PID, PPID and STAT columns, walk a process's parents up to PID 1, and spot zombies. macOS flags noted.

Before thisPipes and pipelinesVariables and the environment

That DevOps Guy · 20 min

Processes: ps, top and the process tree

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by That DevOps GuyReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Every running program is a process with a PID, and every process except the first has a parent PID (PPID) because a process is always created by another process.
  • ps prints a snapshot and top refreshes continuously. Their flags differ between GNU/Linux and macOS, so check man ps before pasting a recipe.
  • The STAT column tells you what a process is doing: S sleeping, R running, T stopped, Z zombie. A + means it is in the foreground of its terminal.
  • A zombie is a finished child whose parent has not collected its exit status. You cannot kill it, you can only get its parent to reap it or exit.
  • When a parent dies first, its children are re-parented to PID 1.

Why a process table exists

When you press Enter on sleep 300, the shell does not become sleep. It asks the kernel for a copy of itself, and that copy replaces its own program with sleep. The shell stays alive and waits. The running copy is a process: a program in motion, with its own memory, open files and an ID.

The kernel needs a way to name each one. That is the PID, a number handed out at creation. It also records who made each process, the PPID. Every process has exactly one parent, so processes form a tree, and the tree has a root, PID 1. On macOS that is launchd. On most Linux systems it is systemd.

Think of it as an org chart where every hire is made by an existing employee, and the chart never has a gap at the top.

Reading ps

I ran everything here on macOS with Bash 5.3, inside a throwaway terminal. Plain ps has a trap on macOS. It does not stop at your current terminal: it listed processes from my unrelated terminal tabs too, so I will not paste that output. Ask for a specific terminal instead:

$ tty
/dev/ttys000
$ ps -t "$(tty)" -o pid,ppid,pgid,stat,command
  PID  PPID  PGID STAT COMMAND
14447 14446 14447 Ss   /opt/homebrew/bin/bash --noprofile --rcfile ...
14477 14447 14477 R+   ps -t /dev/ttys000 -o pid,ppid,pgid,stat,command

Bash is PID 14447. ps itself was started by Bash, so its PPID is 14447. -o picks the columns, which is the part of ps worth memorising. pgid is the process group, which comes back in the job control lesson.

STAT is a letter plus flags. S is sleeping (waiting for something), R running, T stopped, Z zombie. A trailing s marks a session leader and + marks the terminal’s foreground group.

Walking the tree

macOS has no pstree, and ps --forest is GNU-only: here it printed ps: illegal option -- -. You can build the same thing with a loop, which also shows what a PPID is:

$ pid=$$; while [ "$pid" -gt 0 ]; do ps -o pid=,ppid=,comm= -p "$pid"; pid=$(ps -o ppid= -p "$pid" | tr -d ' '); done
14447 14446 /opt/homebrew/bin/bash
14446     1 tmux
    1     0 /sbin/launchd

Bash, whose parent is the tmux server that hosted my test terminal, whose parent is launchd, whose parent is 0 (the kernel itself). The = after each column name drops the header.

Parents, children and orphans

A subshell and a pipeline show how the tree grows:

$ sleep 300 &
$ ( sleep 301 ) &
$ sleep 302 | sleep 303 &
$ ps -o pid,ppid,pgid,stat,command
  PID  PPID  PGID STAT COMMAND   (rows from my other terminals omitted)
14226 14225 14226 Ss   /opt/homebrew/bin/bash ...
14268 14226 14268 S    sleep 300
14275 14226 14275 S    sleep 301
14279 14226 14279 S    sleep 302
14281 14226 14279 S    sleep 303

All four are children of Bash (PPID 14226). The two halves of the pipeline, 14279 and 14281, share a process group, 14279, and that is why Ctrl-C stops both.

What if a parent dies first? In a separate non-interactive test I left a sleep 303 running after its shell exited. ps -o pid,ppid,stat,command later showed it with a PPID of 1. The kernel hands orphans to PID 1, which is built to adopt them.

Zombies

A process that exits leaves a small record behind until its parent reads the exit status with wait. If the parent never does, you get a zombie. I made one on purpose:

$ bash -c 'sleep 0.1 & exec sleep 5' &
$ ps -t "$(tty)" -o pid,ppid,stat,command
  PID  PPID STAT COMMAND
15333 15332 Ss   /opt/homebrew/bin/bash ...
15396 15333 S    sleep 5
15398 15396 Z    <defunct>

The inner sleep 0.1 finished, but its parent, which turned itself into sleep 5 with exec, never calls wait. Z and <defunct> mean a finished process waiting to be collected. It uses no CPU or memory beyond the table slot, and kill cannot help. Once the parent exits, PID 1 reaps it.

top, briefly

ps is a photograph, top a live feed. On macOS the one-shot form is top -l 1, and -n 0 limits the process list to zero lines, leaving the header:

$ top -l 1 -n 0 | sed -n '1,4p'
Processes: 857 total, 4 running, 853 sleeping, 3951 threads
2026/11/23 02:38:21
Load Avg: 2.66, 2.49, 2.10
CPU usage: 13.4% user, 9.5% sys, 77.89% idle

On Linux the procps top takes -b -n 1 for the same job. I did not run that here, so check man top on the machine you use.

About the video

“Understanding Linux Processes” is a 20-minute video from That DevOps Guy (Marcel Dempers), published in November 2026. The page has no chapter list and I could not read a transcript, so I cannot vouch for what it covers beyond the title. It is an English-language channel. The caption track list on the page is long, but that is machine translation, not evidence of the spoken language. It is a Linux video: the flags it uses may differ from the macOS ones above.

Where this fits

You can now see who started what. Next is how to talk to those processes: signals and kill.

Check yourself

  1. 01You run a script and want to find the shell that started it. Which column of ps do you read, and how do you follow the chain further?

    Read PPID, which is the PID of the parent. Look that PID up with ps -p, then read its PPID, and repeat until you reach PID 1.

  2. 02ps shows a process with STAT Z. Why does kill do nothing to it?

    A zombie has already exited and only its table entry is left. There is nothing running to signal. The parent must call wait, or the parent must exit so PID 1 can clean up.

  3. 03A teammate's ps --forest command fails on your Mac. Why?

    --forest is a GNU procps option, and macOS ships the BSD ps, which has no long options. Use ps -axo pid,ppid,command and read the PPID column instead.

  4. 04What does the + in a STAT value like S+ mean?

    The process is in the foreground process group of its controlling terminal, so it receives keyboard signals such as Ctrl-C.

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark