Drill: Trace Process Relationships¶
Goal¶
Use pstree and ps to visualize parent-child process relationships and understand process hierarchies.
Setup¶
- Linux system with procps and pstree installed
- pstree is typically in the
psmiscpackage
Commands¶
Show the full process tree:
Show the tree for a specific PID with thread info:
Show the tree for a specific user:
Use ps in forest mode to see hierarchy with resource info:
Show a specific process and its children:
Find the parent PID of a process:
Trace ancestry from a process back to PID 1:
What to Look For¶
- Services spawned by systemd appear as direct children of PID 1
- Orphaned processes get re-parented to PID 1 or a subreaper
- Worker process models (nginx, apache) show master-worker relationships
- Zombie processes appear with
[defunct]and have exited but not been waited on
Common Mistakes¶
- Confusing threads with child processes in
pstreeoutput (use-tto show threads) - Not using
-pflag and missing which PIDs map to which branches - Forgetting that
ps auxdoes not show hierarchy -- useps auxffor forest mode - Misreading
grepresults that include the grep process itself
Cleanup¶
No cleanup needed. These are read-only inspection commands.