001.phpt 1.8 KB

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