test-pcntl.php 1009 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!../../php -q
  2. <?
  3. declare(ticks=1);
  4. function alarm_handle($signal){
  5. if ($signal==SIGALRM) print "Child: Caught SIGALRM!!!\n";
  6. }
  7. function usr1_handle($signal){
  8. if ($signal==SIGUSR1) print "Child: Caught SIGUSR1!!!\n";
  9. }
  10. print "This test will demonstrate a fork followed by ipc via signals.\n";
  11. $pid=pcntl_fork();
  12. if ($pid==0) {
  13. pcntl_signal(SIGUSR1, "usr1_handle");
  14. pcntl_signal(SIGALRM, "alarm_handle");
  15. print "Child: Waiting for alarm.....\n";
  16. sleep(100);
  17. print "Child: Waiting for usr1......\n";
  18. sleep(100);
  19. print "Child: Resetting Alarm handler to Ignore....\n";
  20. pcntl_signal(SIGALRM, SIG_IGN);
  21. print "Child: sleeping for 10 seconds....\n";
  22. sleep(10);
  23. print "Done\n";
  24. } else {
  25. print "Parent: Waiting 10 seconds....\n";
  26. sleep(10);
  27. print "Parent: Sending SIGALRM to Child\n";
  28. posix_kill($pid,SIGALRM);
  29. sleep(1);
  30. print "Parent: Senging SIGUSR1 to Child\n";
  31. posix_kill($pid,SIGUSR1);
  32. sleep(2);
  33. print "Parent: Sending SIGALRM to Child\n";
  34. pcntl_waitpid($pid, &$status, $options);
  35. }