xref: /PHP-5.4/ext/pcntl/tests/001.phpt (revision f2b8b7f4)
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?>
8--FILE--
9<?php
10function test_exit_waits(){
11	print "\n\nTesting pcntl_wifexited and wexitstatus....";
12
13	$pid=pcntl_fork();
14	if ($pid==0) {
15		sleep(1);
16		exit(-1);
17	} else {
18		$options=0;
19		pcntl_waitpid($pid, $status, $options);
20		if ( pcntl_wifexited($status) ) print "\nExited With: ". pcntl_wexitstatus($status);
21	}
22}
23
24function test_exit_signal(){
25	print "\n\nTesting pcntl_wifsignaled....";
26
27	$pid=pcntl_fork();
28
29	if ($pid==0) {
30		sleep(10);
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}
44
45
46function test_stop_signal(){
47	print "\n\nTesting pcntl_wifstopped and pcntl_wstopsig....";
48
49	$pid=pcntl_fork();
50
51	if ($pid==0) {
52		sleep(1);
53		exit;
54	} else {
55		$options=WUNTRACED;
56		posix_kill($pid, SIGSTOP);
57		pcntl_waitpid($pid, $status, $options);
58		if ( pcntl_wifstopped($status) ) {
59			$signal_print=pcntl_wstopsig($status);
60			if ($signal_print==SIGSTOP) $signal_print="SIGSTOP";
61			print "\nProcess was stoped by signal : ". $signal_print;
62		}
63		posix_kill($pid, SIGCONT);
64	}
65}
66
67print "Staring wait.h tests....";
68test_exit_waits();
69test_exit_signal();
70test_stop_signal();
71?>
72--EXPECT--
73Staring wait.h tests....
74
75Testing pcntl_wifexited and wexitstatus....
76Exited With: 255
77
78Testing pcntl_wifsignaled....
79Process was terminated by signal : SIGTERM
80
81Testing pcntl_wifstopped and pcntl_wstopsig....
82Process was stoped by signal : SIGSTOP
83