1

I am running following code. It's only running parent process.

$pid = pcntl_fork();

if($pid) {
  // parent process runs what is here
  echo $pid;
  echo "parent\n";
}
else {
  // child process runs what is here
  echo "child\n";
}

Output: 1553172parent

I am unable to understand, Why is not running child process.

Tell Me How
  • 672
  • 12
  • 16
  • What is the exact value of `$pid`? According to docs: _On success, the PID of the child process is returned in the parent's thread of execution,_ so is that not the child's PID you are printing out? http://php.net/manual/en/function.pcntl-fork.php – Michael Berkowski Nov 18 '18 at 15:43
  • What platform are you on? The value `1553172` is unusually large for a linux system, where `$pid<32768` should be. – Turbo J Nov 18 '18 at 15:46
  • Architecture: x86_64 Operating System: linux – Tell Me How Nov 18 '18 at 17:05
  • @MichaelBerkowski : My code is never printing "Child" – Tell Me How Nov 18 '18 at 17:10

0 Answers0