I have a scheduled cron job (which is actually a shell script). I'd like to limit the script execution time as it can work unacceptably long. For some reason I can not limit the script execution time from inside the script. Actually, I want my system to force the task termination if it runs more than N hours. Please advise.
質問する
6156 次
2 に答える
21
I'm responding by myself just because none answered.
0 * * * * timeout -s 9 3540 /path/to/your_command.sh
will send a SIGINT to your command if it hasn't completed in 59 minutes.
于 2012-09-04T04:40:21.187 に答える
7
Using an -s 9 is a little extreme as it doesn't let the process do any cleanup. Yes, it will kill the process if it can be killed, but > 90% of the time a -s 1, which requests a graceful hangup, will suffice.
于 2015-07-09T14:39:33.510 に答える