Limit running time to a program

There is no obvious way to specify that a program should run for no longer than x seconds. The following stackoverflow question solves it in a very perlish-way. Define a helper function doalarm:

$ doalarm () { perl -e 'alarm shift; exec @ARGV' "$@"; } # define a helper function

And you are done.

$ doalarm 300 ./my_prog

will run for at most 300 seconds.

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*Required Fields