Reputation: 1065
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?
Upvotes: 0
Views: 227
Reputation: 16185
Try pstree
with the -p
option to show the process tree of a process and its children with pids appended:
$ pstree -p `pgrep pppd`
Upvotes: 1
Reputation: 51583
I'd use ps --ppid ORIGINAL_PROGRAMS_PID
although it might not work if the original program exited.
Upvotes: 0
Reputation: 15834
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
Upvotes: 0