[plug] Killing process after time
Bernard Blackham
bernard at blackham.com.au
Sat May 29 17:58:32 WST 2004
On Sat, May 29, 2004 at 03:42:13PM +0800, Tim White wrote:
> I have a perl script that takes in some numbers does some user interaction
> and then needs to run a process that is killed after a certain amount of
> time.
There's the timeout command (apt-get install timeout).
Or in perl you'd do something like (untested code) :
my $child_pid = fork();
if ($child_pid eq 0) {
exec("/bin/sleep", "10");
/* shouldn't be reached */
exit;
}
$SIG{ALRM} = sub { kill(9, $child_pid) };
alarm(1);
wait();
There's more than likely some dangerous race condition in the above,
but the idea is there :)
HTH,
Bernard.
More information about the plug
mailing list