xref: /PHP-8.0/ext/pcntl/tests/001.phpt (revision c5401854)
1--TEST--
2Test 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    if (PHP_OS == "Darwin") {
8        die("skip do not run on darwin");
9    }
10?>
11--FILE--
12<?php
13function test_exit_waits(){
14    print "\n\nTesting pcntl_wifexited and wexitstatus....";
15
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
27function test_exit_signal(){
28    print "\n\nTesting pcntl_wifsignaled....";
29
30    $pid=pcntl_fork();
31
32    if ($pid==0) {
33        while(1);
34        exit;
35    } else {
36        $options=0;
37        posix_kill($pid, SIGTERM);
38        pcntl_waitpid($pid, $status, $options);
39        if ( pcntl_wifsignaled($status) ) {
40            $signal_print=pcntl_wtermsig($status);
41            if ($signal_print==SIGTERM) $signal_print="SIGTERM";
42            print "\nProcess was terminated by signal : ". $signal_print;
43        }
44
45    }
46}
47
48
49function test_stop_signal(){
50    print "\n\nTesting pcntl_wifstopped and pcntl_wstopsig....";
51
52    $pid=pcntl_fork();
53
54    if ($pid==0) {
55        sleep(1);
56        exit;
57    } else {
58        $options=WUNTRACED;
59        posix_kill($pid, SIGSTOP);
60        pcntl_waitpid($pid, $status, $options);
61        if ( pcntl_wifstopped($status) ) {
62            $signal_print=pcntl_wstopsig($status);
63            if ($signal_print==SIGSTOP) $signal_print="SIGSTOP";
64            print "\nProcess was stopped by signal : ". $signal_print;
65        }
66        posix_kill($pid, SIGCONT);
67    }
68}
69
70print "Staring wait.h tests....";
71test_exit_waits();
72test_exit_signal();
73test_stop_signal();
74?>
75--EXPECT--
76Staring wait.h tests....
77
78Testing pcntl_wifexited and wexitstatus....
79Exited With: 255
80
81Testing pcntl_wifsignaled....
82Process was terminated by signal : SIGTERM
83
84Testing pcntl_wifstopped and pcntl_wstopsig....
85Process was stopped by signal : SIGSTOP
86