proc_get_status()为什么不显示进程已崩溃?

This PHP command-line script runs another script with proc_open():

<?php
$descriptorspec = array(
   0 => array("pipe", "r"),
   1 => array("pipe", "w")
);
$crash = proc_open('php crash.php', $descriptorspec, $pipes);
$status = proc_get_status($crash);
print_r($status);

The inner script just crashes deliberately:

<?php
crash();

I would expect proc_get_status() to tell me the process is no longer running, and has an exit code of 255.

However, this is the output:

Array
(
    [command] => php crash.php
    [pid] => 78769
    [running] => 1
    [signaled] =>
    [stopped] =>
    [exitcode] => -1
    [termsig] => 0
    [stopsig] => 0
)

Why does the status still show it as running?

(I can't use proc_close() in my real use case, as I specifically want to pass multiple things to the inner script and see which one causes it to crash.)

I have modified your code to add while-loop for watching running value returned by proc_get_status

<?php
$descriptorspec = array(
   0 => array("pipe", "r"),
   1 => array("pipe", "w")
);
$crash = proc_open('php crash.php', $descriptorspec, $pipes);
while (true) {
    $status = proc_get_status($crash);
    print_r($status);
    sleep(1);
}

Run above code will output two array side by side, the second one should show running as false as well, It is enough for 1 seconds delay to show the problem of race condition.

$ php modified_demo.php
Array
(
    [command] => php crash.php
    [pid] => 32575
    [running] => 1
    [signaled] =>
    [stopped] =>
    [exitcode] => -1
    [termsig] => 0
    [stopsig] => 0
)
Array
(
    [command] => php crash.php
    [pid] => 32575
    [running] =>
    [signaled] =>
    [stopped] =>
    [exitcode] => 1
    [termsig] => 0
    [stopsig] => 0
)
^C