shell - How to capture a process Id and also add a trigger when that process finishes in a bash script? -
i trying make bash script start jar file , in background. reason i'm using nohup. right can capture pid of java process need able execute command when process finishes.
this how started
nohup java -jar jarfile.jar & echo $! > conf/pid i know this answer using ; make command execute after first 1 finishes.
nohup java -jar jarfile.jar; echo "done" echo "done" example. problem don't know how combine them both. if run echo $! first echo "done" executes immediately. while if echo "done" goes first echo $! capture pid of echo "done" instead of 1 of jarfile.
i know achieve desire functionality polling until don't see pid running anymore. avoid as possible.
you can use bash util wait once start process using nohup
nohup java -jar jarfile.jar & pid=$! # getting process id of last command executed wait $pid # waits until process mentioned pid complete echo "done, execute new command"
Comments
Post a Comment