douting1871 2018-10-18 09:43
浏览 196

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.)

  • 写回答

1条回答 默认 最新

  • dongpu9852 2018-10-18 10:00
    关注

    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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大