Skip to content

Instantly share code, notes, and snippets.

@Exponential-Workload
Created April 12, 2024 15:27
Show Gist options
  • Save Exponential-Workload/859ff186626379fa2673dafe1960e6fb to your computer and use it in GitHub Desktop.
Save Exponential-Workload/859ff186626379fa2673dafe1960e6fb to your computer and use it in GitHub Desktop.
Multi-Exec
#!/bin/bash
cmd_queue=();
push_queue() {
cmd_queue+=("$@")
}
process_queue() {
for cmd in "${cmd_queue[@]}"; do
echo "Running command: $cmd"
$cmd &
pid=$!;
echo "PID: $pid"
pids+=($pid)
done
while : ; do
for i in "${!pids[@]}"; do
if ! kill -0 ${pids[i]} 2> /dev/null; then
echo "Command ${cmd_queue[i]} exited. Killing other processes..."
kill "${pids[@]:$i}" 2> /dev/null
exit 1
fi
done
done
}
# ur silly commands here
push_queue "crond -n"
if [ "$@" != "" ]; then
push_queue "$@"
fi;
process_queue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment