You'll probably want to use fork/exec for this. You'll probably find the perlipc pod useful. Here's a small, very lightly tested example to get you going. Good luck!
#!/usr/bin/perl -l use strict; use warnings; spawn(5, "/tmp/cmd.pl"); sub spawn { my ($timeout, @cmd) = @_; defined( my $child_pid = fork ) or die "fork: $!"; if ($child_pid) { # parent eval { local $SIG{ALRM} = sub { timeout($child_pid); }; alarm $timeout; waitpid $child_pid, 0; alarm 0; }; if ($@) { print "oops: $@"; } } else { # child exec @cmd or die "exec: $!"; } } sub timeout { my ($pid) = @_; kill 'TERM' => $pid; waitpid $pid, 0; die "reaped $pid\n"; }
In reply to Re: Re: Re: Re: Re: Re: Re: Passing function to a function using \&<function name> method
by edan
in thread Passing function to a function using \&<function name> method
by rich_d_thomas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |