How to time out a program in bash
Steve Flynn
anothermindbomb at gmail.com
Tue Oct 6 18:34:39 UTC 2009
On Tue, Oct 6, 2009 at 6:22 PM, Kevin O'Gorman <kogorman at gmail.com> wrote:
> 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?
If the $TMOUT environmental variable is set to a non-zero value time,
then the shell prompt will
time out after $time seconds. This will cause a logout.
If you can persuade the students to use some supplied code:
TIMELIMIT=4 # 4 seconds
read -t $TIMELIMIT variable <&1
#
# In this instance, "<&1" is needed for Bash 1.x and 2.x,
# but unnecessary for Bash 3.x.
--
Steve
When one person suffers from a delusion it is insanity. When many
people suffer from a delusion it is called religion.
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
More information about the ubuntu-users
mailing list