Wikipedia:Reference desk/Archives/Computing/2017 October 9

= October 9 =

Runtime Limit
What is the best way to set a runtime limit on a process in Linux? If the cronjob foobar.sh doesn't finish within an hour I want it to be killed. Dragons flight (talk) 17:54, 9 October 2017 (UTC)


 * One way is to use the timeout command; for example

timeout 3600 foobar.sh
 * will send SIGTERM to the foobar.sh process after it has been running for one hour. But you need to make sure that foobar.sh exits cleanly when it receives SIGTERM. CodeTalker (talk) 19:55, 9 October 2017 (UTC)


 * Note that this limits the amount of elapsed time, not CPU time. StuRat (talk) 00:09, 10 October 2017 (UTC)


 * Thanks. Dragons flight (talk) 04:13, 10 October 2017 (UTC)


 * To limit CPU time, use ulimit, which is a bash built-in; for example

ulimit -t 3600; foobar.sh
 * --69.159.60.147 (talk) 02:10, 10 October 2017 (UTC)