Skip to content

proc_close after proc_get_status always returns -1 #10239

Closed

Description

@pezcurrel

Description

The following code:

<?php
$p = proc_open('sleep 1', array(), $foo);
do {
    usleep(100000);
    $s = proc_get_status($p);
    echo $s['running'] ? 'Running' : 'Finished', PHP_EOL;
} while ($s['running']);
echo proc_close($p), PHP_EOL;

Resulted in this output:

Running
Running
Running
...
Finished
-1

But I expected this output instead:

Running
Running
Running
...
Finished
0

PHP Version

PHP 8.1.13

Operating System

Arch Linux

Activity

  1. ndossche commented on Jan 6, 2023

    @ndossche
    Member

    This also fails:

    <?php
    $p = proc_open('sleep 1', array(), $foo);
    usleep(2*1000*1000);
    var_dump(proc_get_status($p)); // correct result here
    var_dump(proc_get_status($p)); // wrong result here (-1 exit code)

    It's because once you read the status, the zombie goes away and you can't read it again. I'll take a look to patch this.

  2. added 2 commits that reference this issue on Feb 18, 2023
    62dc267
    9c514e8
  3. added a commit that references this issue on Jul 8, 2026
    25d6c93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions