--- name: fork status: documented runtime: pp source: src/runtime/pp/process.rs --- ```{index} single: fork; Perl built-in (pp runtime) ``` # fork ## Synopsis ```perl 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