ps and pstree: See the Process Tree in CI
ps -ef --forest draws the process tree so you can see which parent spawned a runaway or orphaned child.
A test that leaves background processes behind, or a shell that spawns a daemon that outlives the job, shows up clearly as a tree. ps --forest and pstree both render it.
What it does
ps with --forest (or f in BSD syntax) indents children under parents so the spawn hierarchy is visible. pstree does the same more compactly. Together with the PPID column they reveal orphans (reparented to PID 1) and zombies (state Z, defunct, waiting to be reaped).
Common usage
ps -ef --forest
ps axf # BSD-style tree
pstree -p 4242 # tree under one PID, with PIDs
ps -eo pid,ppid,stat,comm | awk '$3 ~ /Z/' # list zombiesOptions
| Flag | What it does |
|---|---|
| -ef | Every process, full format (PPID, start, cmd) |
| --forest | Draw the parent/child tree |
| axf | BSD-syntax equivalent of -ef --forest |
| -o <fields> | Choose columns, e.g. pid,ppid,stat,comm |
| pstree -p | Compact tree, annotate with PIDs |
In CI
When a job "finishes" but the runner hangs cleaning up, a child process is still alive. ps -ef --forest shows it parented to PID 1 (orphaned). Kill the whole subtree with the parent PID, or use a process group: setsid your command and kill -- -<pgid> on cleanup so no child survives. The note: existing pages ps-command and ps-command-reference cover the base command; this page is the tree view.
Common errors in CI
A process stuck in state Z (zombie/defunct) cannot be killed; it is already dead and waiting for its parent to reap it. Killing the parent lets init reap the zombie. State D (uninterruptible sleep) means the process is blocked in the kernel on I/O and will not respond to SIGKILL until that I/O returns.