Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-05-12 07:57:26

0001 #!/usr/bin/env bash
0002 set -euo pipefail
0003 
0004 N=$1
0005 shift
0006 declare -a pids=()
0007 
0008 # Start all processes in the background
0009 for i in $(seq 1 "$N"); do
0010     # Replace `sleep 10` with the actual command you want to run.
0011     # For demonstration, we are using a command that sleeps for 10 seconds.
0012     # Make sure it runs in the background with '&'.
0013     "$@" &
0014     pids+=($!)
0015 done
0016 
0017 # Wait for all processes to finish, if any fails, kill them all
0018 for pid in "${pids[@]}"; do
0019     if ! wait "$pid"; then
0020         echo "Process $pid failed. Terminating all remaining processes..."
0021         # Kill all started processes
0022         kill "${pids[@]}" 2>/dev/null || true
0023         exit 1
0024     fi
0025 done
0026 
0027 echo "All processes completed successfully."
0028 exit 0