Skip to content

Instantly share code, notes, and snippets.

@chernjie
Last active April 16, 2018 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chernjie/6234c95466f8ec1f09f2e180d0a8617c to your computer and use it in GitHub Desktop.
Save chernjie/6234c95466f8ec1f09f2e180d0a8617c to your computer and use it in GitHub Desktop.
#!/bin/sh
rundir=/var/run/parallelLimit
pause_file="$rundir/paused"
harakiri_file="$rundir/good-day-to-die"
is-paused() {
[ -f "$pause_file" ]
}
is-time-to-die() {
[ -f "$harakiri_file" ]
}
run() {
for i in $(seq 1 16); do
(
while true; do
is-time-to-die && exit
if is-paused; then
sleep 60
else
/path/to/do-job
fi
done
) &
done
wait
}
pause() {
touch "$pause_file"
}
unpause() {
rm -f "$pause_file"
}
stop() {
touch "$harakiri_file"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment