AlwaysALearner AlwaysALearner - 1 month ago 16
Bash Question

How to get child process from parent process

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

Just use :

pgrep -P $your_process1_pid