# alarmtest.pl use strict; use Win32::Process; my @commands = @ARGV; timeout(@commands); print "End of test"; sub timeout { my ($time, $exe, $command) = @_; my ($obj, $exit, $counter); Win32::Process::Create($obj, $exe, $command, 1,NORMAL_PRIORITY_CLASS | CREATE_NEW_PROCESS_GROUP, '.') || die; { $obj->GetExitCode( $exit ) ; # the following constant isn't in # Win32::Process docs, but seems to # be true for my system at least. last unless $exit == 259; last if $counter++ >= ($time * 4); select(undef, undef, undef, 0.25); redo; }; if ($exit == 259) { print "Timed out!\n"; $obj->Kill(1); }; } #### sleep_unless_lockfile (200, "$ENV{TEMP}\\lockfile"); sub sleep_unless_lockfile { my ($sleeptime, $lockfile)=@_; my $counter; { sleep 1; $counter++; print "$counter."; last if (-e $lockfile); last if $counter >= $sleeptime; redo; } }