Skip to content
Create a gist now

Instantly share code, notes, and snippets.

@zba /output
Last active

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
perl sleep test
$ time ./
real 0m6.020s
user 0m0.004s
sys 0m0.008s
sleep 6
a=`./ 2 ./`
use strict;
use warnings;
my $PID=$$;
my $timeout=shift;
my @args=@ARGV;
my $pid = fork();
defined $pid or die "fork: $!";
$pid == 0 && exec(@args);
my $timed_out = 0;
$SIG{ALRM} = sub { $timed_out = 1; die; };
alarm $timeout;
eval { waitpid $pid, 0 };
alarm 0;
if ($timed_out) {
print "Timed out!\n";
kill 9, $pid;
kill 9,$PID;
elsif ($@) {
warn "error: $@\n";

changing kill 9, $pid; to kill 9, $PID; not helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.