Skip to content

Commit 53b8c64

Browse files
committed
Fix test: use SIGKILL via /bin/sh instead of posix_kill
PHP catches SIGTERM internally and does exit(255), so the child process never actually dies from the signal. Use /bin/sh with kill -9 (SIGKILL) which cannot be caught.
1 parent a22d029 commit 53b8c64

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

ext/standard/tests/general_functions/proc_close_signal_exit_code.phpt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@ proc_close() returns 128+signal when child is killed by a signal
33
--SKIPIF--
44
<?php
55
if (PHP_OS_FAMILY === 'Windows') die('skip Not for Windows');
6-
if (!function_exists('posix_kill') || !function_exists('posix_getpid')) die('skip posix extension required');
6+
if (!is_executable('/bin/sh')) die('skip /bin/sh not available');
77
?>
88
--FILE--
99
<?php
1010

11-
// Child that kills itself with SIGTERM (15)
12-
$child = '<?php posix_kill(posix_getpid(), 15);';
13-
11+
// Shell that kills itself with SIGKILL (9) — cannot be caught
1412
$process = proc_open(
15-
[PHP_BINARY, '-r', $child],
13+
['/bin/sh', '-c', 'kill -9 $$'],
1614
[['pipe', 'r'], ['pipe', 'w'], ['pipe', 'w']],
1715
$pipes
1816
);
@@ -22,14 +20,12 @@ foreach ($pipes as $pipe) {
2220
}
2321

2422
$exitCode = proc_close($process);
25-
// Should be 128 + 15 = 143
23+
// Should be 128 + 9 = 137
2624
var_dump($exitCode);
2725

2826
// Child that exits normally with code 42
29-
$child2 = '<?php exit(42);';
30-
3127
$process2 = proc_open(
32-
[PHP_BINARY, '-r', $child2],
28+
['/bin/sh', '-c', 'exit 42'],
3329
[['pipe', 'r'], ['pipe', 'w'], ['pipe', 'w']],
3430
$pipes2
3531
);
@@ -44,5 +40,5 @@ var_dump($exitCode2);
4440

4541
?>
4642
--EXPECT--
47-
int(143)
43+
int(137)
4844
int(42)

0 commit comments

Comments
 (0)