001.phpt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. --TEST--
  2. Test pcntl wait functionality
  3. --EXTENSIONS--
  4. pcntl
  5. posix
  6. --SKIPIF--
  7. <?php
  8. if (PHP_OS == "Darwin") {
  9. die("skip do not run on darwin");
  10. }
  11. ?>
  12. --FILE--
  13. <?php
  14. function test_exit_waits(){
  15. print "\n\nTesting pcntl_wifexited and wexitstatus....";
  16. $pid=pcntl_fork();
  17. if ($pid==0) {
  18. sleep(1);
  19. exit(-1);
  20. } else {
  21. $options=0;
  22. pcntl_waitpid($pid, $status, $options);
  23. if ( pcntl_wifexited($status) ) print "\nExited With: ". pcntl_wexitstatus($status);
  24. }
  25. }
  26. function test_exit_signal(){
  27. print "\n\nTesting pcntl_wifsignaled....";
  28. $pid=pcntl_fork();
  29. if ($pid==0) {
  30. while(1);
  31. exit;
  32. } else {
  33. $options=0;
  34. posix_kill($pid, SIGTERM);
  35. pcntl_waitpid($pid, $status, $options);
  36. if ( pcntl_wifsignaled($status) ) {
  37. $signal_print=pcntl_wtermsig($status);
  38. if ($signal_print==SIGTERM) $signal_print="SIGTERM";
  39. print "\nProcess was terminated by signal : ". $signal_print;
  40. }
  41. }
  42. }
  43. function test_stop_signal(){
  44. print "\n\nTesting pcntl_wifstopped and pcntl_wstopsig....";
  45. $pid=pcntl_fork();
  46. if ($pid==0) {
  47. sleep(1);
  48. exit;
  49. } else {
  50. $options=WUNTRACED;
  51. posix_kill($pid, SIGSTOP);
  52. pcntl_waitpid($pid, $status, $options);
  53. if ( pcntl_wifstopped($status) ) {
  54. $signal_print=pcntl_wstopsig($status);
  55. if ($signal_print==SIGSTOP) $signal_print="SIGSTOP";
  56. print "\nProcess was stopped by signal : ". $signal_print;
  57. }
  58. posix_kill($pid, SIGCONT);
  59. }
  60. }
  61. print "Staring wait.h tests....";
  62. test_exit_waits();
  63. test_exit_signal();
  64. test_stop_signal();
  65. ?>
  66. --EXPECT--
  67. Staring wait.h tests....
  68. Testing pcntl_wifexited and wexitstatus....
  69. Exited With: 255
  70. Testing pcntl_wifsignaled....
  71. Process was terminated by signal : SIGTERM
  72. Testing pcntl_wifstopped and pcntl_wstopsig....
  73. Process was stopped by signal : SIGSTOP