[Bug 292255] pdgetpid wrongly succeeds for processes that have already been waited

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 07 Jan 2026 20:10:08 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=292255

            Bug ID: 292255
           Summary: pdgetpid wrongly succeeds for processes that have
                    already been waited
           Product: Base System
           Version: 16.0-CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: asomers@FreeBSD.org

pdgetpid(2) can lookup the pid corresponding to a particular process
descriptor.  A common use case is to wait on a child, since there is no such
thing as pdwait4().

When using a function like waitpid(pid, ..., WEXITED), it is very important not
to call it twice for the same pid.  Doing so could lead to inadvertently
waiting on an unrelated process after the desired process has exited.

In its current form, pdgetpid() will still return the original pid, even after
the child has died and been waited upon.  That's a bug, IMHO, because it can
lead to users calling waitpid() on the same pid twice.

IMHO, pdgetpid should return ESRCH in this case.

See the attached file for an ATF test case that demonstrates the problem.

-- 
You are receiving this mail because:
You are the assignee for the bug.