[sf-perl] not understanding program behavior with alarm()
David Alban
extasia at extasia.org
Fri Feb 3 14:43:00 PST 2012
greetings,
my code is not doing what i expect. i have:
$ cat junk.test.alarm
#!/usr/bin/perl
use strict;
use warnings;
eval {
local $SIG{ ALRM } = sub { die "alarm\n"; };
alarm 5;
system 'bash', "$ENV{ HOME }/junk.sh";
alarm 0;
};
if ( $@ ) {
if ( $@ eq "alarm\n" ) {
die "timed out!\n";
}
else {
die "non-timeout error: $!\n";
}
}
print "right before exit stmt\n";
exit 0;
and:
$ cat ~/junk.sh
#!/bin/bash
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
i=0
while true ; do
i=$(( $i + 1 ))
echo $i
sleep 1
done
exit 0
when i run, i get:
$ perl junk.test.alarm
$ perl junk.test.alarm
1
2
3
4
5
timed out!
dalban at srwd00reg008 Fri Feb 03 22:41:37
~
$ 6
7
8
9
10
11
12
13
with junk.sh continuing until i kill it from the command line.
what am i missing?
should the die() stop junk.sh?
thanks,
david
--
Live in a world of your own, but always welcome visitors.
***
Rule of law is for the little people.
http://www.amazon.com/Liberty-Justice-Some-Equality-Powerful/dp/0805092056
More information about the SanFrancisco-pm
mailing list