Chris Samuel <[email protected]> writes:
> Hi folks,
>
> This is likely an easy one, but my brain is fading rapidly at the moment..
>
> Is there a way to easily collect all child (and grandchild, etc)
> processes of a particular process?
>
> I know I can do ps --ppid $PID to get the immediate children, and I can
> use pstree -p $PID to see all the descendants in graphical form, but I
> want to get an easy to parse list.
>
> Any ideas, or is this a case of writing it myself?
HTFU and write it. It's just simple recursion.
$ f(){ for i; do x=$(pgrep -P $i)&& { echo $x;f $x; } ;done; }
Testing:
$ ps fux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
twb 25223 0.0 0.1 4572 1072 tty1 S+ Jun16 0:09 screen -DRR
twb 20322 2.8 5.8 47476 43724 ? Ss Jun18 395:58 emacs --daemon
twb 1056 0.4 1.6 15988 12548 ? Ss Jun10 126:37 SCREEN -DRR
twb 1057 0.0 0.0 3372 464 ? S Jun10 0:00 \_ tail -f
/home/twb/.emacs.d/irc-activity
twb 20318 0.0 0.0 1588 600 pts/0 Ss+ Jun18 0:00 \_
emacsclient --tty -c
twb 5927 1.3 2.1 20044 16236 pts/3 Ss+ 10:33 0:40 \_ emacs -f
gnus
twb 6444 0.5 0.3 5976 2936 pts/1 Ss 11:18 0:01 \_ bash
twb 6532 0.0 0.1 4192 872 pts/1 R+ 11:21 0:00 | \_ ps fux
twb 6514 7.0 0.3 5976 2928 pts/2 Ss 11:21 0:00 \_ bash
twb 6531 0.5 0.0 3344 432 pts/2 S+ 11:21 0:00 \_ sleep
1h
twb 1051 0.0 0.0 2664 720 ? Ss Jun10 0:01
//bin/dbus-daemon --fork --print-pid 4 --print-address 6 --session
twb 1050 0.0 0.0 4592 588 ? Ss Jun10 2:32 gpg-agent
--daemon
twb 1042 0.0 0.0 2628 524 ? Ss Jun10 1:46 ssh-agent -t12h
$ f 1056
1057 5927 6444 6514 20318
6531
$
_______________________________________________
luv-main mailing list
[email protected]
http://lists.luv.asn.au/listinfo/luv-main