fork#

Synopsis#

my $pid = fork();
die "fork failed: $!" unless defined $pid;
if ($pid == 0) {
    # child process
    exit(0);
} else {
    # parent process, $pid is child's PID
    waitpid($pid, 0);
}

Description#

Creates a child process by duplicating the current process.

Calls POSIX fork(2) to create a new child process. Both parent and child continue execution from the point of the fork call.

Returns:

  • undef on failure (fork could not be performed)

  • 0 in the child process

  • The child’s PID (positive integer) in the parent process

See also#

exec, wait, waitpid, exit