159 /usr/sbin/inetd -s
26072 in.telnetd
26074 -ksh
4771 /usr/local/bin/ksh trap11.ksh
4772 /usr/local/bin/ksh trap11.ksh
4773 /usr/local/bin/ksh trap11.ksh
4774 /bin/sleep 1
I need Linux equivalent. ps --forest -eaf works, but
I have to get ALL PIDs. Why ps --forest --pid does not work?
pstree -a -p works some what, but if you gives a child ID, it does
show the whole tree. -H would get the whole PIDs in the system.
What is the closest match to solaris simple ptree command output?
--
Michael Wang * http://www.unixlabplus.com/ * mw...@unixlabplus.com
> 159 /usr/sbin/inetd -s
> 26072 in.telnetd
> 26074 -ksh
> 4771 /usr/local/bin/ksh trap11.ksh
> 4772 /usr/local/bin/ksh trap11.ksh
> 4773 /usr/local/bin/ksh trap11.ksh
> 4774 /bin/sleep 1
> I need Linux equivalent. ps --forest -eaf works, but
> I have to get ALL PIDs. Why ps --forest --pid does not work?
It does.
> pstree -a -p works some what, but if you gives a child ID, it does
It works perfectly. Why the "-a"?
> show the whole tree. -H would get the whole PIDs in the system.
Mind rephrasing your question in better english? I don't see what
pstree -p doesn't get you.
Peter
>> pstree -a -p works some what,
> It works perfectly. Why the "-a"?
To include command-line arguments, which Solaris ptree evidently does.
>> but if you gives a child ID, it does
>> show the whole tree. -H would get the whole PIDs in the system.
> Mind rephrasing your question in better english? I don't see what
> pstree -p doesn't get you.
More specifically:
'pstree -a -p 123' will show process 123 and its descendants, with
arguments and process IDs.
'pstree -a -p -H 123' will show all processes, with arguments and
process IDs, and with process 123 and its ancestors highlighted.
Considering this tree:
root 1659 1 0 Jul06 ? 00:00:20 /usr/sbin/sshd
root 1835 1659 0 Jul06 ? 00:00:00 \_ /usr/sbin/sshd
root 1837 1835 0 Jul06 pts/0 00:00:00 | \_ -dtksh
root 3716 1659 0 20:45 ? 00:00:01 \_ /usr/sbin/sshd
root 3719 3716 0 20:46 pts/1 00:00:02 \_ -bash
[root@localhost tmp]# ps --forest --pid 3719 | more
PID TTY TIME CMD
3719 pts/1 00:00:02 bash
does not get me the tree.
[root@localhost tmp]# pstree -a -p 3719
bash,3719
`-pstree,3869 -a -p 3719
does not give the tree either.
They just give me a branch.
while ps --forest -eaf gives the whole forest.
So on Linux, I either get a branch (too little) or a forest (too much).
I need a tree like what shown at the beginning.
> Considering this tree:
>
> root 1659 1 0 Jul06 ? 00:00:20 /usr/sbin/sshd
> root 1835 1659 0 Jul06 ? 00:00:00 \_ /usr/sbin/sshd
> root 1837 1835 0 Jul06 pts/0 00:00:00 | \_ -dtksh
> root 3716 1659 0 20:45 ? 00:00:01 \_ /usr/sbin/sshd
> root 3719 3716 0 20:46 pts/1 00:00:02 \_ -bash
>
> [root@localhost tmp]# ps --forest --pid 3719 | more
> PID TTY TIME CMD
> 3719 pts/1 00:00:02 bash
>
> does not get me the tree.
>
> [root@localhost tmp]# pstree -a -p 3719
> bash,3719
> `-pstree,3869 -a -p 3719
>
> does not give the tree either.
>
> They just give me a branch.
>
> while ps --forest -eaf gives the whole forest.
>
> So on Linux, I either get a branch (too little) or a forest (too much).
> I need a tree like what shown at the beginning.
You have to specify the root of the tree. 'pstree -a -p 1659' will
give you what you want.
Or do you want to specify a descendant and display the tree rooted at
its second-oldest ancestor? Here's some plumbing for you:
#!/bin/sh
pstree -a -p `pstree -a -p -H $1 | grep '1m.*0m' | head -2 | tail +2 | sed -e
's/^.*,//' -e 's/).*$//'`
Save this as a text file ~/bin/ptree (assuming ~/bin is in your PATH)
Note that it is two lines long, with a very long second line (which may
wrap in your newsreader).
'chmod o+x ~/bin/ptree'
Now you can 'ptree 3719' and get what you want.
1m is part of ANSI highlight-on; 0m is part of ANSI highlight-off.
It works on my system, at least. I'm sure it could be improved in any
number of ways, but it's good enough for light interactive use.