How to time out a program in bash
Kevin O'Gorman
kogorman at gmail.com
Wed Oct 7 02:24:57 UTC 2009
On Tue, Oct 6, 2009 at 11:45 AM, James Michael Fultz <croooow at gmail.com>wrote:
> * Kevin O'Gorman <kogorman at gmail.com> [2009-10-06 10:22 -0700]:
> > I'm not sure where to ask this, but surely there are bash script
> > experts watching...
> >
> > I'm trying to write a bash script to test a some student programs.
> > Some of them get wedged, and I can use ulimit to catch most of that.
> > However, if they wedge reading stdin when they are not supposed to,
> > ulimit does not catch them.
> >
> > Can a bash script use an alarm? Anybody have a quick recipe? Or
> > another approach?
>
> #v+
> timer () {
> # use 60 seconds for timeout, set accordingly
> sleep 60 && kill $$
> }
>
> # start the timer
> timer & timerpid=$!
>
> # execute whatever needs to have a timeout...
>
> # if we've made it through, stop the timer
> kill "$timerpid"
> #v-
>
> Thanks, James. This looks like it has what I need.
++ kevin
--
Kevin O'Gorman, PhD
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20091006/9790bcac/attachment.html>
More information about the ubuntu-users
mailing list