[14405 views]

[]

[toggle ads]

Timeout kill

Did you ever have to deal with a runaway process? A runaway process I call a program that appears to "hang" and needs to be killed to terminate. Effects like that are a reality. And we shouldn't ignore them. They are very annoying when they occur in automated processes. Such as cron jobs. We need a way to set an upper time limit to a processes runtime.

Whenever possible you should use the GNU timeout program from GNU Coreutils.

However there are Linux/Unix systems that come without that program. Here is a small rewrite as a Bash script. timeout is a small shell script that does just that: send a signal to a process after some time if it hasn't died yet and wait for it to die. The following would for instance terminate mplayer playing a video stream after five minutes:

timeout -TERM 5m mplayer tv://

If you have suggestions for improvement (in the form of a patch), please feel free to contact me.

Download

timeout and a few simple test cases: test-timeout