> -----Original Message-----
> From: chad kellerman [mailto:[EMAIL PROTECTED]]
> Sent: Friday, July 12, 2002 12:57 PM
> To: [EMAIL PROTECTED]
> Subject: Fork to run a sub -process
>
>
> Hi everyone,
>
> I am stuck. I have a perl script that I wrote. It runs
> on a Solaris 8
> box and goes out to linux boxes and tars up user data and
> mysql data and
> stores it on particular drives of the sun box.
>
> Right now the script only goes out and tars up one server
> at a time. I was
> thinking of putting that process as a sub routine and try to
> go out and
> "backup" two servers (or three) at a time.
>
> I am thinking I should try and fork child processes to do
> each server. The
> child being the sub routine.
>
> What do you think? Would this be the best way to go about
> this? Where is
> the best resource for examples on forking? I am going
> through google groups
> but most of them entail system calls or networking. Not a
> sub routine.
The Perl Cookbook from O'Reilly has nice examples, IMO.
The basic idea is really quite simple:
Iterative example:
for my $server (qw(huey duey louie)) {
do_lengthy_process($server);
}
sub do_lengthy_proces
{
... blah blah ...
}
Forking example:
for my $server (qw(huey duey louie)) {
defined(my $pid = fork) or die "Couldn't fork: $!";
unless ($pid) {
do_lengthy_process($server);
exit;
}
}
That's really all you need to do.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]