Take the 2-minute tour ×

Is there any way to find the pid of children of a program ?

For example I'm starting pppoe connection using system program:

pon dsl-provider

The program will exit after establishing connection and will spawn a pppd needed for connection:

ps wx | grep pppd
  882 ?        S      0:01 /usr/sbin/pppd call dsl-provider

The thing is (I was doing that until now) that I don't want to grep in ps listing, I want an exact answer, and I need this in many circumstances (the above is only an example). How can I do that?

share|improve this question
One hopefully useful hint, that you can use in conjunction with both below answers: If you are ready do background the original process pon dsl-provider & you can get its PID with $!. –  ArjunShankar May 24 '12 at 13:01
add comment

3 Answers

Try pstree with the -p option to show the process tree of a process and its children with pids appended:

$ pstree -p `pgrep pppd`
share|improve this answer
add comment

You can try this

# somehow get the PID of the parent (882 in your case)
PID=`ps wx | grep pppd | awk '{ print $1; }'`

# formatted output (includes the parent)
ps ax --format pid,ppid,command | grep $PID | grep -v grep
share|improve this answer
add comment

I'd use ps --ppid ORIGINAL_PROGRAMS_PID although it might not work if the original program exited.

share|improve this answer
add comment

Your Answer


