Use PID of child process in bashPosted: July 4, 2014
Launch a child process, get its PID, show a message, wait for the child to complete and show another message:
ls -R /var >> /dev/null & echo PID $! running; wait $!; echo PID $! completed
- Use of & after the command is mandatory, or else you will not get the PID you want.
- Using asynchronous execution in combination with wait command is, obviously, equivalent to using a synchronous call, except that it gives you more power.
- Using wait with no arguments will make the parent process to wait for all children it ever spawned, using wait with a PID will make it wait only for that particular process.