How to get child process from parent process

AlwaysALearner picture AlwaysALearner · Jul 19, 2013 · Viewed 171.8k times · Source

Is it possible to get the child process id from parent process id in shell script?

I have a file to execute using shell script, which leads to a new process process1 (parent process). This process1 has forked another process process2(child process). Using script, I'm able to get the pid of process1 using the command:

cat /path/of/file/to/be/executed

but i'm unable to fetch the pid of the child process.

Answer

Miklos Aubert picture Miklos Aubert · Jul 19, 2013

Just use :

pgrep -P $your_process1_pid