if I launch a bash script as a child, I can pass its own pid to the parent by using $$.
Is there any way to find the pid of a program that I launch from a script in
Use this: $! right after executing the command whose PID you want. It means, though that you need to use an ampersand (&) after the command, to start it in background. E.g.:
$!
&
my_command & CMDPID=$! echo "$CMDPID"
The variable $! has the PID of the last background process you started.