in reply to Re: Re: Re: Re: Re: Re: Passing function to a function using \&<function name> method
in thread Passing function to a function using \&<function name> method
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: Re: Re: Re: Passing function to a function using \&<function name> method
by rich_d_thomas (Sexton) on Mar 03, 2004 at 22:22 UTC | |
|
Re: Re: Re: Re: Re: Re: Re: Re: Passing function to a function using \&<function name> method
by rich_d_thomas (Sexton) on Mar 04, 2004 at 21:44 UTC | |
by edan (Curate) on Mar 08, 2004 at 13:41 UTC | |
by Anonymous Monk on Mar 18, 2004 at 21:29 UTC | |
by rich_d_thomas (Sexton) on Apr 03, 2004 at 13:02 UTC |