If you know the process ID, you can use the wait
command, which is bash builtin:
wait PID
You can get the PID of the last run of the command in bash with $!
. Or you can grep for it with ps
output.
In fact, the wait command is a useful way to run the parralel command in bash. Here is an example:
# Start the processes in parallel... ./script1.sh 1>/dev/null 2>&1 & pid1=$! ./script2.sh 1>/dev/null 2>&1 & pid2=$! ./script3.sh 1>/dev/null 2>&1 & pid3=$! ./script4.sh 1>/dev/null 2>&1 & pid4=$! # Wait for processes to finish... echo -ne "Commands sent... " wait $pid1 err1=$? wait $pid2 err2=$? wait $pid3 err3=$? wait $pid4 err4=$? # Do something useful with the return codes... if [ $err1 -eq 0 -a $err2 -eq 0 -a $err3 -eq 0 -a $err4 -eq 0 ] then echo "pass" else echo "fail" fi
source share