とりあえずあとで書くメソッド。
ちょこっとだけ書いてみる。
ソースはまだ読んでない...
実は内部でps読んでるだけじゃないかとか疑ってみたり...
Linuxの方が何か使いやすそう。
ちょこっと見てみたら、defineで定義してるPSCMDってのがそうみたい。つか、
ps -eo uid,pid,ppid,pgid,args
って何??? こんなオプションがあるとはさすがGNU謹製...
# やっぱ手元にSolarisほしいな...検証できん
Solarisの場合
> uname -a SunOS XXXX 5.10 Generic sun4u sparc SUNW,Serverblade1 > pstree --help pstree: illegal option -- help pstree $Revision: 2.27 $ by Fred Hucht (C) 1993-2004 EMail: fred AT thp.Uni-Duisburg.de Usage: pstree [-f file] [-g] [-u user] [-U] [-s string] [-p pid] [-w] [pid ...] -f file read input from <file> (- is stdin) instead of running "ps -ef" -g n use graphics chars for tree. n=1: IBM-850, n=2: VT100 -u user show only branches containing processes of <user> -U don't show branches containing only root processes -s string show only branches containing process with <string> in commandline -p pid show only branches containing process <pid> -w wide output, not truncated to window width pid ... process ids to start from, default is 1 (init) use 0 to also show kernel processes > pstree -u youichi -+= 00000 root 0:28 sched \-+- 00001 root 0:10 /sbin/init \-+- 00316 root 0:00 /usr/lib/ssh/sshd \-+- 15409 root /usr/lib/ssh/sshd \-+- 15412 youichi /usr/lib/ssh/sshd \-+- 15414 youichi -tcsh \-+- 15556 youichi pstree -u youichi \-+- 15557 youichi sh -c ps -ef \--- 15558 youichi ps -ef
Linuxの場合
$uname -a Linux XXXX.co.jp 2.4.21-15.ELsmp #1 SMP Sun May 16 01:48:39 EDT 2004 i686 i686 i386 GNU/Linux $pstree --help pstree: オプションが違います -- - usage: pstree [ -a ] [ -c ] [ -h | -H pid ] [ -l ] [ -n ] [ -p ] [ -u ] [ -G | -U ] [ pid | user] pstree -V -a show command line arguments -c don't compact identical subtrees -h highlight current process and its ancestors -H pid highlight process "pid" and its ancestors -G use VT100 line drawing characters -l don't truncate long lines -n sort output by PID -p show PIDs; implies -c -u show uid transitions -U use UTF-8 (Unicode) line drawing characters -V display version information pid start at pid, default 1 (init) user show only trees rooted at processes of that user $pstree -u youichi ssh ssh ssh ssh sshd---tcsh---pstree $pstree -ah youichi ssh cvsXXX cvs\040server ssh cvsXXX cvs\040server ssh cvsXXX cvs\040server ssh cvsXXX cvs\040server sshd `-tcsh `-pstree -ah youichi
GNUのps入れてLinuxのifdefのとこをSolarisでも有効にしたらコンパイルできるかなぁ...?
ま、一筋縄じゃいかないんだろうけれど...