Skip to content

Instantly share code, notes, and snippets.

@klueska
Created January 11, 2017 23:17
Show Gist options
  • Save klueska/44c77c7090672d185b821f164c195fd7 to your computer and use it in GitHub Desktop.
Save klueska/44c77c7090672d185b821f164c195fd7 to your computer and use it in GitHub Desktop.
#!/bin/bash
declare -a pids
NUM_LOGGERS=$1
cleanup() {
echo "Caught SIGINT/HUP/TERM - Cleaning up PIDs.."
for p in ${pids[@]}
do
echo "Cleaning up PID ${p}"
kill -15 ${p}
done
}
trap cleanup 1 2 15 # HUP INT TERM
echo_seq() {
while true
do
echo {0..1000}
sleep 0.05
done
}
echo "Script PID $$"
for n in `seq $NUM_LOGGERS`
do
(echo_seq) | systemd-cat & pid=$!
echo "Forked worker ${n}, PID ${pid}"
pids+=($pid)
done
# Keep parent process alive to accept signals and execute trap func
sleep infinity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment