fork
Does a fork(2) system call. Returns the child pid to the parent process
and 0 to the child process, or undef if the fork is unsuccessful.
Note: unflushed buffers remain unflushed in both processes, which means
you may need to set $| ($AUTOFLUSH in English) or call the
autoflush() FileHandle method to avoid duplicate output.
If you fork() without ever waiting on your children, you will accumulate
zombies:
$SIG{'CHLD'} = sub { wait };
There's also the double™fork trick (error checking on
fork() returns omitted);
unless ($pid = fork) {
unless (fork) {
exec "what you really wanna do";
die "no exec";
some_perl_code_here;
exit 0;
}
exit 0;
}
waitpid($pid,0);
|
|
|