Skip to content

getProcessExitCode/waitForProcess should throw ECHILD rather than return ExitSuccess for non-child process #359

@alt-romes

Description

@alt-romes

https://www.man7.org/linux/man-pages/man2/wait.2.html

       ECHILD (for waitpid() or waitid()) The process specified by pid
              (waitpid()) or idtype and id (waitid()) does not exist or
              is not a child of the calling process.  (This can happen
              for one's own child if the action for SIGCHLD is set to
              SIG_IGN.  See also the Linux Notes section about threads.)

In https://github.com/well-typed/haskell-debugger, it took me a long while to uncover a bug that turned out to be caused by getProcessExitCode incorrectly returning Just ExitSuccess for a handle of a non-child process.

I'm "unsafely" (i.e with .Internals) constructing the handle from the PID of a process that was not spawned/is not a child of the process calling getProcessExitCode. It should throw something like ECHILD, following the manpage for wait.

I suspect waitForProcess should also fail with ECHILD here.

I've attached the AI generated counter example program I was using to observe the incorrect behavior outside of the much more complicated haskell-debugger

NonChildProcessHandleDemo.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions