> -----Original Message-----
> From: George Szynal [mailto:[EMAIL PROTECTED]]
> Sent: Friday, July 12, 2002 1:34 PM
> To: Bob Showalter; 'chad kellerman'; [EMAIL PROTECTED]
> Subject: Re: Fork to run a sub -process
> 
> 
> Where is the command that runs inside the fork (ie. 
> _lengthy_process running
> in the fork)?

In my example, I assume that do_lengthy_process is a normal
perl sub that does whatever the OP was wanting to do. It can
make system calls or whatever...

I don't know what you mean by "inside the fork". fork creates
a new process. after the fork, there are two identical copies
of the original process running. The only difference is that
$pid is 0 for the child and non-zero for the parent. If $pid
is zero, the child runs the lengthy process and then exits.
The parent skips the lengthy process and loops back around to
fork the next child.

> 
> 
> </snip>
> Forking example:
> 
>     for my $server (qw(huey duey louie)) {
>         defined(my $pid = fork) or die "Couldn't fork: $!";
> 
> # forked command(s) begin/end here?
>         unless ($pid) {
>             do_lengthy_process($server);                      
>       # runs
> unforked if fork fails

No. we will only get here if the fork succeeded. If the fork fails,
we die above.

>             exit;
>         }
>     }
> <snip>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to