in reply to Question on how fork works.

When a process forks execution continues in two processes at the same point. The difference is that in parent process the fork() returns the PID of the child and in the child it returns undef. So, in your example the parent enters the first branch of the if block and the child enters the second.

Perl didn't invent this behavior - fork() is just a think wrapper around the normal UNIX fork() system call. The behavior is the same.

-sam

Replies are listed 'Best First'.
Re: Re: Question on how fork works.
by mattriff (Chaplain) on Jul 01, 2002 at 02:02 UTC
    The docs describe it just a little differently. According to perlfunc, it returns 0 (zero) to the child process. undef is returned to the parent if the fork fails.

    - Matt Riffle

      Good point. I should have kept it to what I knew and said it returned false.

      -sam