2 ms·
For long-running jobs which need to be killed after a timeout, and when you also need to ensure there is only ever a single instance, use something like this:
by gjvc 6y ago
For long-running jobs which need to be killed after a timeout, and when you also need to ensure there is only ever a single instance, use something like this:
/usr/bin/flock --nonblock /var/tmp/${LOGNAME}.sleep \
/usr/bin/timeout --signal KILL 5 \
/usr/bin/sleep 10
Where your command goes in place of the "/usr/bin/sleep 10" (If this is not immediately obvious, to see it in action, open two terminals on the same host, and try running the above command in both at the same time.)