Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like to show a listing of a single process and its current children. So, given the following process tree:

Imagine the following process listing:

  PID TTY      STAT   TIME COMMAND
    2 ?        S      0:00 [kthreadd]
    3 ?        S      0:06  \_ [ksoftirqd/0]  
  ...snip...
 1292 ?        Ss     0:06 /usr/sbin/gpm -m /dev/input/mice -t exps2
 1426 ?        Ss     0:00 /usr/lib/postfix/master
 9785 ?        S      0:00  \_ qmgr -l -t fifo -u
12301 ?        S      0:00  \_ pickup -l -t fifo -u -c
 1545 ?        Ss     0:05 /usr/sbin/apache2 -k start
 1570 ?        S      0:00  \_ /usr/sbin/apache2 -k start  
  ...snip...

I would like to instead just show process 1426 and its children. Like this:

  PID TTY      STAT   TIME COMMAND
 1426 ?        Ss     0:00 /usr/lib/postfix/master
 9785 ?        S      0:00  \_ qmgr -l -t fifo -u
12301 ?        S      0:00  \_ pickup -l -t fifo -u -c

Is there a simple way to do this?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

You can use pstree to do this and get a nicely formatted output too

pstree -p 22221
mysqld_safe(22221)─┬─logger(22334)
                   └─mysqld(22332)─┬─{mysqld}(22335)
                                   ├─{mysqld}(22336)
                                   ├─{mysqld}(22337)
                                   ├─{mysqld}(22338)
                                   ├─{mysqld}(22340)
                                   ├─{mysqld}(22341)
                                   ├─{mysqld}(22342)
                                   ├─{mysqld}(22343)
                                   ├─{mysqld}(22346)
                                   └─{mysqld}(22394)
share|improve this answer
add comment
$ ps -p 1426 --ppid 1426 --forest

or:

$ ps -eo pid,ppid,tty,stat,time,command --forest | awk '$1 == 1426 || $2 == 1426'

to display the details command.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.