diff options
author | asami <asami@FreeBSD.org> | 1999-06-22 14:47:21 +0800 |
---|---|---|
committer | asami <asami@FreeBSD.org> | 1999-06-22 14:47:21 +0800 |
commit | ae29a41bdc2cd5bfcfbdbe657344a6473d28ef68 (patch) | |
tree | b41d2903aa04aadcd58bf2ebda1d4a244844edd4 /Tools/portbuild | |
parent | db214e395ed16f36edbd8644ddc649c7da5bb309 (diff) | |
download | freebsd-ports-gnome-ae29a41bdc2cd5bfcfbdbe657344a6473d28ef68.tar.gz freebsd-ports-gnome-ae29a41bdc2cd5bfcfbdbe657344a6473d28ef68.tar.zst freebsd-ports-gnome-ae29a41bdc2cd5bfcfbdbe657344a6473d28ef68.zip |
A perl script to run a command with a timeout. The command is killed if it
doesn't complete within the specified timeout period.
I tried to do this from within the pdispatch script, but I couldn't
get all the auxiliary processes to be killed correctly so implemented
this as a separate script in perl.
Diffstat (limited to 'Tools/portbuild')
-rwxr-xr-x | Tools/portbuild/scripts/ptimeout | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Tools/portbuild/scripts/ptimeout b/Tools/portbuild/scripts/ptimeout new file mode 100755 index 000000000000..53e28b77c3ae --- /dev/null +++ b/Tools/portbuild/scripts/ptimeout @@ -0,0 +1,38 @@ +#!/usr/bin/perl -w +# ptimeout: executes command but kills it after a specified timeout +# usage: ptimeout timeout command args ... +$timeout=$ARGV[0]; +splice(@ARGV, 0, 1); +#print "timeout is ", $timeout, "\n"; +#print "arguments are ", "@ARGV", "\n"; +if ($pid1 = fork) { + if ($pid2 = fork) { + # parent + #print 'child pids are ', $pid1, ' ', $pid2, "\n"; + $child=wait; + $status=$?; + #print "exited child is $child, status is $status\n"; + if ($pid1 = $child) { + #print "killing process $pid2\n"; + kill 'TERM', $pid2; + } + else { + #print "killing process $pid1\n"; + kill 'TERM', $pid1; + } + # exit status in upper 8 bits, killed signal (if any) in lower 8 bits + exit (($status >> 8) | ($status & 0xff)) ; + } + else { + # second child + sleep $timeout; + print "ptimeout: killing @ARGV (pid $pid1) since timeout of $timeout expired\n"; + kill 'TERM', $pid1; + exit 1; + } +} +else { + # first child + print "executing @ARGV\n"; + exec @ARGV; +} |