Help on ps tree listing command - Linux/Solaris


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help on ps tree listing command - Linux/Solaris
# 1  
Old 01-21-2013
Help on ps tree listing command - Linux/Solaris

Hi all,

Can any guru please help on how I can tweak the following ps command so that it only shows the lines that I wanted.

Code:
 
 
$ command ps -HAcl -F S -A f
 
F S UID        PID  PPID CLS PRI ADDR SZ WCHAN    RSS PSR STIME TTY        TIME CMD
4 S root         1     0 TS   24 -  2592 ?        684   4  2012 ?        59368:31 init [3]
1 S root         2     1 FF  139 -     0 migrat     0   0  2012 ?          0:17 [migration/0]
1 S root         3     1 TS    5 -     0 ksofti     0   0  2012 ?          0:00 [ksoftirqd/0]
...
...
...
5 S root     11953     1 TS   24 - 39673 ?       8520  21  2012 ?         13:49 /usr/sbin/snmpd -Lf /dev/null -p /var/run/snmpd.pid -a
5 S root     11982     1 TS   24 - 15662 ?       1212   7  2012 ?        372:27 /usr/sbin/sshd
4 S root       586 11982 TS   23 - 22537 ?       3336   9 15:25 ?          0:00  \_ sshd: ben [priv]
5 S ben        714   586 TS   24 - 22537 ?       1864  18 15:25 ?          0:01      \_ sshd: ben@pts/3
0 S ben        718   714 TS   24 - 16229 wait    1588   7 15:25 pts/3      0:00          \_ -ksh
4 S root       801   718 TS   23 - 25270 wait    1372  14 15:25 pts/3      0:00              \_ su - oracle
4 S oracle     856   801 TS   24 - 16553 wait    1732  19 15:25 pts/3      0:45                  \_ -bash
1 S oracle    9282   856 TS   22 - 16553 wait     808  19 17:47 pts/3      0:00                      \_ -bash
0 R oracle    9284  9282 TS   20 - 16753 -       2284  12 17:47 pts/3      0:00                      |   \_ ps -HAcl -F S -A f
0 S oracle    9283   856 TS   21 - 15253 -        572  13 17:47 pts/3      0:00                      \_ more
1 S root     11996     1 TS   24 -  5416 ?        884   9  2012 ?          0:00 xinetd -stayalive -pidfile /var/run/xinetd.pid
5 S ntp      12017     1 TS   24 -  5853 ?       5044  20  2012 ?          0:56 ntpd -x -u ntp:ntp -p /var/run/ntpd.pid
4 S root     12079     1 TS   24 - 13545 ?       2316  21  2012 ?          0:10 /usr/libexec/postfix/master
4 S postfix  12094 12079 TS   24 - 13605 ?       2420   9  2012 ?          0:00  \_ qmgr -l -t fifo -u

I want the command to only display the ones that is related to my ssh session which are the ones in RED.

To be more specific, I am wanting to display a ps tree listing by providing the PPID.

I tried running the same command and including a -p [PPID] but that still does restrict the listing.

Also tried running the same command in Solaris and it is saying

Code:
 
$: ps -HAcl -F S -A f
ps: illegal option -- H
ps: illegal option -- F
usage: ps [ -aAdeflcjLPyZ ] [ -o format ] [ -t termlist ]
        [ -u userlist ] [ -U userlist ] [ -G grouplist ]
        [ -p proclist ] [ -g pgrplist ] [ -s sidlist ] [ -z zonelist ]
  'format' is one or more of:
        user ruser group rgroup uid ruid gid rgid pid ppid pgid sid taskid ctid
        pri opri pcpu pmem vsz rss osz nice class time etime stime zone zoneid
        f s c lwp nlwp psr tty addr wchan fname comm args projid project pset

Anyone know what's the equivalent option to use in Solaris?

Feedback / advice is much appreciated. Thanks in advance.
# 2  
Old 01-21-2013
Did you have a look at pstree command (linux)?
# 3  
Old 01-21-2013
On the Linux box save the following script as "ptree":
Code:
#!/bin/sh
# Solaris style ptree
# by HP Michael Tosch

[ -x /usr/bin/ptree ] && exec /usr/bin/ptree "$@"

PATH=/bin:/usr/bin:/usr/sbin:/sbin
export PATH

psopt="-e"
case $1 in
-*)
 echo "
Usage: ptree [ PID | USER ]
Print process tree
 PID : extract branch for this process
 USER : filter for this (existing) user
 USER PID : do both
"
 exit;;
[0-9]*);;
?*)
 psopt="-u $1"
 shift;;
esac
psopt="$psopt -H -o pid= -o args="

if [ -z "$1" ]; then
 ps $psopt
 exit
fi

#some effort to add less to the ps list
tmp=/tmp/ptree.$$
trap 'rm $tmp' 0 HUP INT TERM
ps $psopt >$tmp
<$tmp awk '
{ ci=index(substr($0,6),$2); o[ci]=$0 }
ci>s[a] { s[++a]=ci }
$1==pid {
 for(i=1;i<=a;i++) {
  si=s[i]; if(si<=ci) print o[si]
 }
 walkdown=ci
 next
}
ci<=walkdown { exit }
walkdown!=0 { print }
' pid="$1"

Now run e.g.
ptree 586 or
ptree 9282 or
ptree 9283
and you'll get the relevant branch from the ps tree.
This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 01-25-2013
Hi,

Had checked on pstree but I don't have the time stuff

---------- Post updated at 04:28 PM ---------- Previous update was at 04:27 PM ----------

Thanks MadeInGermany,

I will have a test on this.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Port listing Solaris and Linux

I'd like to list all ports and the services allocated to them: 1) What commands will do this on Solaris 10 and Linux? 2) Is there a file containing the port/service mapping? (1 Reply)
Discussion started by: squrcles
1 Replies

2. UNIX for Dummies Questions & Answers

How to find directory listing from root to all files in tree format with details of perm/own/grp?

Hi, My apologies if my query is already available on this forum but I am new and could not find. I need a script to list all directories/sub directories and files with permissions/groups/owners. The script would run from home directory and should capture every directory. How do I do this? ... (4 Replies)
Discussion started by: 8709711
4 Replies

3. UNIX for Dummies Questions & Answers

Tree command

How can i install tree command in ubundu without root ? I have found some shell script which does the same job as tree but i would like to get all the options in tree command thanks (2 Replies)
Discussion started by: gvj
2 Replies

4. Programming

How to modify all Makefiles in a source tree into linux environment

Hi Frndz, I am new to the makefile generation. I have a source code which contains makefiles in each sub-directories. Previously we have used the entire source code in Dtbuild environment to get the executables. Now have to change the current Dtbuild environment to Linux build... (1 Reply)
Discussion started by: korraag
1 Replies

5. Solaris

Install tree for Solaris 10

I'm an trying to install U6 on Xen in Opensolaris. I would like to make this VM para-virtualized to maximize performance but it requires an install tree. I'm not real familiar with an install tree. I can use full virtualization and use an .iso which I have without issues but I would like to use the... (1 Reply)
Discussion started by: Lespaul20
1 Replies

6. UNIX for Dummies Questions & Answers

tree command

In DOS, to get the complete directory structure, we use 'TREE' command.. can anyone tell me what is the equivalent command in Unix I am using SunOS ABC 5.8 Generic_117350-18 sun4u sparc SUNW,Sun-Fire-V240 thanks.. (1 Reply)
Discussion started by: wip_vasikaran
1 Replies

7. Solaris

Not able to copy the tree node text in solaris, while easily done in window

I m not able to copy the text present on the tree's node to terminal or other text editor in solaris. I m using <Shift><control> C and V comaand for the same but the text is not being copied and pasted on the text pad or the terminal window. While the same is possible in windows OS using ctrl+c... (3 Replies)
Discussion started by: friendanoop
3 Replies

8. Filesystems, Disks and Memory

How to find the total size of a dirctory tree in Solaris

Hi, I want to find the total size of some directory trees in my solaris 9 machine. Is there a command or utility I can use to do it. Please let me know if there is any way. Thanks Akheel (1 Reply)
Discussion started by: 0ktalmagik
1 Replies

9. UNIX for Dummies Questions & Answers

what is the command for listing the device specs in solaris

Im looking to get the statistics on a machine memory, cpu speed drive size etc thanks in advance (3 Replies)
Discussion started by: simplimarvelous
3 Replies
Login or Register to Ask a Question