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

Computing desk
< October 8 << Sep | October | Nov >> Current desk >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


October 9

edit

Runtime Limit

edit

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)[reply]

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)[reply]
Note that this limits the amount of elapsed time, not CPU time. StuRat (talk) 00:09, 10 October 2017 (UTC)[reply]
Thanks. Dragons flight (talk) 04:13, 10 October 2017 (UTC)[reply]
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)[reply]