> -----Original Message----- > From: Jason Frisvold [mailto:[EMAIL PROTECTED]] > Sent: Thursday, September 19, 2002 10:49 AM > To: Bob Showalter > Cc: [EMAIL PROTECTED] > Subject: RE: Forking, Passing Parameters to forks > > > Hrm ... So, I could create an array of parameters to send, plus the > hash for the data and the forked process would have this information > available?
Yes. > Now what happens if the main program modifies these > variables? They are only modified in the parent. After the fork, the parent and child lead separate lives. Presumably, the parent would adjust some values before forking the next child, so that child has different stuff to do. > Is the fork in a different memory space? The child is a separate process and memory space from the parent. When it starts, its memory space is an exact copy of the parent's memory space. > > Do the forked processes start from the beginning or continue on from > that point? The child begins execution immediately following the fork call. They way for the child to know he's the child is that fork() returns 0. The parent gets a non-zero return. So, the "classic" fork construct is: defined(my $pid = fork) or die "Couldn't fork: $!"; unless ($pid) { # child runs here ... exit; # exit to keep from running parent code below } # parent continues here ... forking is *real* simple unless the parent and child have to coordinate their activities, or if children have to coordinate among one another. At that point, you need to use the various IPC mechanisms (signals, pipes, file locking, semaphores, etc.). > > Yes, I'm headed over to look up fork now .. :) > > perldoc -f fork .. right? Yup. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]