On Tue, 2002-03-26 at 01:14, Ahmed Moustafa wrote:
> Jim Conner wrote:
> > At 20:28 03.25.2002 -0800, Ahmed Moustafa wrote:
> > 
> >>> Jim Conner wrote:
> >>>
> >>>> I suck at this kind of topic but the only way I can think of doing 
> >>>> such a thing is this:
> >>>>
> >>>> Use IPC.
> >>>>
> >>>> fork off something like 10 children each child working on a separate 
> >>>> file and use sysvmsg sysvshem (I do not believe these are functions 
> >>>> and I can't look the right functions up for you right now but 
> >>>> perldoc perlipc might be of some use) to pass messages back and 
> >>>> forth between the children and the parent to follow what each 
> >>>> process is doing.
> >>>
> >>>
> >>> 'fork' spawns a child process of the parent, doesn't it?
> >>
> >>
> >> I mean the child is a clone of the parent, isn't?
> > 
> > 
> > Yes; from the point where the fork occurs.
> 
> So, how can a new different process by forked? Or, how a function be 
> called and the next step execute without waiting for the previous 
> function to terminate?

Fork returns 0 to the child process and the pid of the child process to
the parent.  This allows you to say things like

my @children;
#loop while get_filename retruns a vaild filename
#this could easily be a foreach loop of @filenames
while (my $filename = get_filename()) { 
        my $forked = fork; #fork into two processes(parent and child)

        #if $forked is undef then fork failed
        unless (defined $forked) {
                warn "something went wrong with fork";
                next;
        } 

        #push the PID of the child onto a stack
        push @children, $forked; #meaningless for child
        
        next if $forked; #parent loops

        #only the child can get here 
        encrypt_the_file($filename);

        #child ends execution here
        exit 0;
}

#reap the children to avoid zombies
waitpid $_ for (@children); 


-- 
Today is Setting Orange the 12nd day of Discord in the YOLD 3168
Keep the Lasagna flying!

Missile Address: 33:48:3.521N  84:23:34.786W


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

Reply via email to