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