1--TEST--
2Test function pcntl_fork() by testing the process isolation in the forking hierarchy father -> son -> grandson where father can not knows his grandson
3--CREDITS--
4Marco Fabbri mrfabbri@gmail.com
5Francesco Fullone ff@ideato.it
6#PHPTestFest Cesena Italia on 2009-06-20
7--SKIPIF--
8<?php
9    if (!extension_loaded('pcntl')) die('skip pcntl extension not available');
10    elseif (!extension_loaded('posix')) die('skip posix extension not available');
11?>
12--FILE--
13<?php
14echo "*** Testing the process isolations between a process and its forks ***\n";
15
16$pid = pcntl_fork();
17
18if ($pid > 0) {
19  pcntl_wait($status);
20  echo "father is $pid\n";
21
22  if (!isset($pid2))
23  {
24    echo "father ($pid) doesn't know its grandsons\n";
25  }
26}
27else
28{
29  echo "son ($pid)\n";
30  $pid2 = pcntl_fork();
31  if ($pid2 > 0)
32  {
33    pcntl_wait($status2);
34    echo "son is father of $pid2\n";
35  }
36  else
37  {
38    echo "grandson ($pid2)\n";
39  }
40}
41?>
42--EXPECTF--
43*** Testing the process isolations between a process and its forks ***
44son (0)
45grandson (0)
46son is father of %d
47father is %d
48father (%d) doesn't know its grandsons
49