brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: pstree -p shows which process started which on Linux, with PIDs

Linux
~/tips/tip-linux-pstree-p

pstree -p

Draws the running processes as a tree, so you see parents, children and their PIDs.

ps aux gives you a flat list, and working out which process started which is guesswork. pstree draws the family tree.

pstree -p

-p adds the PID of each process in parentheses. Add -a to see the command-line arguments too, which helps when ten processes are all called python3.

You can start the tree at one process or show the processes of one user:

pstree -p 1234
pstree -s -p 1234
pstree www-data

The first shows 1234 and everything below it. -s adds the parents above it, so you see what launched it: a systemd service, a cron job or a shell in a tmux session. The last one shows the trees of processes owned by www-data.

-u marks every place where the user changes between parent and child, which makes it easy to spot a root process that starts something as another user, or the reverse.

Caveat: -p and -a turn off the compact view that merges identical branches, so on a busy server the output gets long. Pipe it into less, or start from the PID you care about instead of from the top. On some minimal distros and containers, pstree is not installed; it comes in the psmisc package.

Further reading: pstree manual

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link