note 69198 modified in function.pcntl-fork by danbrown
| From: | danbrown@php.net | Date: | Tue, 10 Aug 2010 15:46:58 +0000 |
| Subject: | note 69198 modified in function.pcntl-fork by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171541@lists.php.net to get a copy of this message | ||
I think this simple code can help understand how fork works:
<?php
echo "posix_getpid()=".posix_getpid().",
posix_getppid()=".posix_getppid()."\n";
$pid = pcntl_fork();
if ($pid == -1) die("could not fork");
if ($pid) {
echo "pid=".$pid.", posix_getpid()=".posix_getpid().",
posix_getppid()=".posix_getppid()."\n";
} else {
echo "pid=".$pid.", posix_getpid()=".posix_getpid().",
posix_getppid()=".posix_getppid()."\n";
}
?>
--was--
I think this simple code can help understand how fork works:
<?
echo "posix_getpid()=".posix_getpid().",
posix_getppid()=".posix_getppid()."\n";
$pid = pcntl_fork();
if ($pid == -1) die("could not fork");
if ($pid) {
echo "pid=".$pid.", posix_getpid()=".posix_getpid().",
posix_getppid()=".posix_getppid()."\n";
} else {
echo "pid=".$pid.", posix_getpid()=".posix_getpid().",
posix_getppid()=".posix_getppid()."\n";
}
?>
http://php.net/manual/en/function.pcntl-fork.php