getProcessExitCode/waitForProcess should throw ECHILD rather than return ExitSuccess for non-child process
- Dominant language
- Haskell
- Stars
- 91
- Forks
- 91
- PR merge metrics
- No merged PRs in 30d
Description
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](https://github.com/user-attachments/files/26755074/NonChildProcessHandleDemo.txt)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the implementations of getProcessExitCode and waitForProcess, then run the attached NonChildProcessHandleDemo.txt example to reproduce the behavior. Compare handling of a non-child process with the wait(2) ECHILD semantics; done means both functions no longer report ExitSuccess for that case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100