commands

pstree — process hierarchy

Show a process tree rooted at PID, with numeric identifiers using -p. Tree membership can change while inspecting. Use a fresh private workspace, ordinary user and bounded child processes; no sudo.

Formal Syntax & Structure

linux syntaxlinux
pstree -p PID

Parameters & Attributes

NameTypeDescription
-poptionshow PIDs
PIDoperandroot process ID

Return Value

exit status and output

Show a process tree rooted at PID, with numeric identifiers using -p. Tree membership can change while inspecting.

Working Example

Example Snippetlinux
sleep 2 &child=$!rc=0tree=$(pstree -p "$$") || rc=$?wait "$child" || exit 1test "$rc" -eq 0 || exit 1printf "%s\n" "$tree" | grep -F "sleep($child)" >/dev/null || exit 1printf "child in tree\n"
Linux Reference