Created
January 11, 2017 23:17
-
-
Save klueska/44c77c7090672d185b821f164c195fd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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