How can I get the entire process tree spawned by a given process displayed as a tree and only that tree i.e. no other processes?
The output could e.g. look like
4378 ? Ss 0:10 SCREEN
4897 pts/16 Ss 0:00 \_ -/bin/bash
25667 pts/16 S+ 0:00 | \_ git diff
25669 pts/16 S+ 0:00 | \_ less -FRSX
11118 pts/32 Ss+ 0:00 \_ -/bin/bash
11123 pts/32 S+ 0:00 \_ vi
I couldn't get the desired result purely with parameters to ps.
The following gives the desired result but seems a bit involved:
#!/bin/bash
pidtree() {
echo -n $1 " "
for _child in $(ps -o pid --no-headers --ppid $1); do
echo -n $_child `pidtree $_child` " "
done
}
ps f `pidtree 4378`
Does anyone have an easier solution?
ps auxf. – jftuga Nov 30 '11 at 21:34