Let’s say you have three scripts. You want to execute them simultaneously (or as close to simultaneous as is practicable). You then want to examine all of their exit statuses, and maybe perform some actions accordingly.
The easiest way is using a script such as the following, capturing the PID of each process as it is launched, and then using wait to wait for the specified process to return its termination status. For example:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#!/bin/ksh # of course, these don't have to be scripts - any executable will do /path/to/a.sh & pid_a=$! /path/to/b.sh & pid_b=$! /path/to/c.sh & pid_c=$! wait $pid_a echo "a.sh returned $?" wait $pid_b echo "b.sh returned $?" wait $pid_c echo "c.sh returned $?" exit 0 |