bash - Wait for last created process (daemon which forks) to end -


i'm writing wrapper script use in inittab. script starts daemon , waits terminate.

here's have currently:

#!/bin/bash  /usr/local/bin/mydaemon --lots_of_params_here while kill -0 `echo $!` 2> /dev/null; sleep 1; done; 

the problem second line; returns immediately. if instead do:

while kill -0 `pgrep mydaemon` 2> /dev/null; sleep 1; done; 

it works fine, isn't solution me have other scripts prefix mydaemon.

what doing wrong?

edit:

the problem seems related daemon fork(). so, parent pid in $!. i'm looking ways solve problem. maybe should use pid files , have mydaemon write pid there.

you can following way through issue.

#!/bin/bash /usr/local/bin/mydaemon --lots_of_params_here & wait $! 

wait command wait till process completes , comes out.

if looking wait after other commands can store pid in other variable , use that.

#!/bin/bash /usr/local/bin/mydaemon --lots_of_params_here & mypid=$! ### other commands wait $mypid 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -