On Wed, 14 Mar 2001, Billigmeier, Chad wrote:

> My question for you all is if fork is called, can the parent do one thing
> and the child do another and if so how?

> Say for example, Id like the parent to fish() and the child to cut_bait(). 

fork() in perl is the same as the standard Unix fork() call in C, so your
best bet is to look at the "fork" man page.  Also see page 715 of
the Camel Book (3rd edition).

You call fork() once but you return from it twice, once in the
parent process and once in the child.  The function returns 
a non-zero process ID in the parent, but returns 0 in the child.
So you'd write something like this:

if ($pid = fork()) {
    # this is the parent
    fish();
} else {
    # this is the child ($pid is 0)
    cut_bait();
}
# anything after here will be excuted by BOTH processes!

Pay careful attention to the comment at the end.  To avoid it,
you may want the parent, or the child, or both, to exit() 
or exec() before reaching it.
 
--
Ron Newman       [EMAIL PROTECTED]
URL: http://www2.thecia.net/users/rnewman/

Reply via email to