From nobody Sat Aug 1 12:19:28 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hC2744FY8z6mty6 for ; Sat, 01 Aug 2026 12:19:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hC2742SCPz49yf for ; Sat, 01 Aug 2026 12:19:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785586768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TPmKM0AuBzR4EOhR+zOJXQWZILwBLPJ0bYBdzbJcFg4=; b=E2LzUHa2SXb6CTA7tcr3Huhlr86YmbRQbhEvppx5SMKo7H6pS/x2WDtWzp0MVPNOI+7xWw ZFm4w3igEZeN5UISwyRU2ePLnsVr1Ze6yf01/wTp/gX5+hX4fIlsMW6TGlJX5tcTPoIc3o LXTtxJsywDHJhN54Na6zktCxKC0VUzzZ9n3GEaPLrBTBrmW7SZKhy//r3k8ljEHOyPopsw dWOP0fAyeQ8RyWR9APLXunn5EsgJ9t+GdLsZkcTXgCj3w7bzipQ3P2YnmZrhkftIfZbOhh kuIIvc+rXboI8dhXPJRIGnbsVH0rRX4QB8ntHcYcb6y9vaoc74Gu+DrHgOH0/Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785586768; a=rsa-sha256; cv=none; b=JIPfRT4Qlv+MEVrvir+30URYKBR2E1vtuGGBlSW6EJSPhtkX/Y+U4AhKTu2dbictjOhF3f Vy32LkAjEuu1HqYmqM8kcKRot9DweRyDQw5EpAlMj+lWsPuy44+UJvPpQ/fWKqL9DzwdMd oQUc3liqyF2f2tRSQjbATd1MS70GB6gWg6D7fk4mwwy4biJf67aeaHnndOw8dll69KLwUq 2BjFrROerhz5mOk7wL57obrCb3AemWOgLUaaVAsl/2owTHOiaqYdZSW9aMLQT63NnJhhGf XTHe+63SIV0PwbWofm/6SK5BEhdVZJznrGkwJLpA2YMAS3pz6sFe9ESrYEA7mQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785586768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TPmKM0AuBzR4EOhR+zOJXQWZILwBLPJ0bYBdzbJcFg4=; b=EC504T9UpEXZJgJqa/RhWnkqhWgoEIMUYHuGdIrNuhwmC92/C6Uuju2E1ek4R0mLFpA2KC 9qrJL10rj7b4AQDAqZQ4eqNBdnzvTxM6KLXQdtSVdiH5TeYoYTeT9OHK5tNAq1Afc2yb2J jxA0iARaYcjiN3pkdeQbFICo3aaKIHmw7H/9/FmqkfNb7GnjyfWHt6PXiNzfiv5a76Ek+L 3GOa4j8PxqT6q8nIWZI0pbAgyBZQWwMJo8VEeLigV0u8XDsrjJiQkvUQ6Y4BTX0U5VesVS 1NHZB4PE76qnhmJ21PrlPYwbLO5dOykJhLqp9usSPqO2fh9cqZ3TuSFWaya4lw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hC2740mymzksM for ; Sat, 01 Aug 2026 12:19:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1d50a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 01 Aug 2026 12:19:28 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: c49198534a9b - main - pdwait(2), wait(2): document interaction between pdopenpid() and waitpid() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c49198534a9b823c18c8b9e67e3b16a2d0fa27ad Auto-Submitted: auto-generated Date: Sat, 01 Aug 2026 12:19:28 +0000 Message-Id: <6a6de450.1d50a.33695179@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=c49198534a9b823c18c8b9e67e3b16a2d0fa27ad commit c49198534a9b823c18c8b9e67e3b16a2d0fa27ad Author: Konstantin Belousov AuthorDate: 2026-07-21 20:03:46 +0000 Commit: Konstantin Belousov CommitDate: 2026-08-01 10:41:54 +0000 pdwait(2), wait(2): document interaction between pdopenpid() and waitpid() Reviewed by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D58264 --- lib/libsys/pdfork.2 | 61 +++++++++++++++++++++++++++++++++++++++++++++++++---- lib/libsys/wait.2 | 9 -------- 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/lib/libsys/pdfork.2 b/lib/libsys/pdfork.2 index 1b99157203c1..6f577427a716 100644 --- a/lib/libsys/pdfork.2 +++ b/lib/libsys/pdfork.2 @@ -103,6 +103,9 @@ specifying the flag, closing that descriptor kills the process. .It Dv PD_CLOEXEC Set close-on-exec on process descriptor. +.It Dv PD_NOWAITPID +The parent cannot obtain the child's status with +.Xr waitpid 2 . .El .Pp The @@ -149,9 +152,6 @@ to succeed. Zombie processes cannot be opened. .Pp There might be more that one file descriptor referencing the process. -But only one caller of -.Fn pdwait -gets the exit status. After the zombie is reaped, calls to .Fn pdwait specifying any file descriptors for the same process fail with the @@ -176,7 +176,7 @@ the status information on the process referenced by the .Fa fd process descriptor. See the description of the -.Xr wait6 +.Xr wait6 2 system call for the behavior specification. .Pp The @@ -197,6 +197,59 @@ The argument is reserved and must be zero. Certain file descriptor types cannot be copied this way, namely kqueues. +.Sh INTERACTION OF PROCESS DESCRIPTORS AND Xr WAITPID 2 +.Pp +The +.Fn pdwait +system call may be called on a process descriptor +an unlimited number of times. +In particular, it does not reap the target process, +even if that process has exited. +Each time, it returns the same status. +.Bl -dash +.It +If the process was forked with +.Fn pdfork , +and the +.Dv PD_NOWAITPID +flag was specified, then the process is automatically reaped after the +last process descriptor referencing that process is closed. +No +.Xr waitpid 2 +call +.Pq or a call from the same family of the wait functions which operate on PIDs +are needed to reap the zombie process. +.It +If the process was created by +.Fn pdfork , +and the +.Dv PD_NOWAITPID +flag was not specified, then after exiting, +the process will not be reaped until the parent or reaper has called +.Xr waitpid 2 +and all process descriptors referencing the process are closed. +.It +If the process was created by the +.Xr fork 2 +system call +.Pq which does not allocate a process descriptor for the child , +and later the process was opened by +.Fn pdopenpid , +then a +.Xr waitpid 2 +call from the parent is needed to reap the exited child. +.El +.Pp +In any case, the PID of the process is not reused until its zombie +is reaped, and all its process descriptors are closed. +.Pp +A debugger attached by +.Xr ptrace 2 +can execute the +.Fn waitpid +calls against the alive target regardless of the way +the target process was forked. +.Sh INTERACTION OF PROCESS DESCRIPTORS WITH OTHER SYSTEM CALLS .Pp The following system calls also have effects specific to process descriptors: .Pp diff --git a/lib/libsys/wait.2 b/lib/libsys/wait.2 index ca289c69f188..f018ab3d4d37 100644 --- a/lib/libsys/wait.2 +++ b/lib/libsys/wait.2 @@ -607,15 +607,6 @@ fields of .Fa infop must be checked against zero to determine if a process reported status. .Pp -The -.Fn wait -family of functions will only return a child process created with -.Xr pdfork 2 -if the calling process is not in -.Xr capsicum 4 -capability mode, and -.Nm -has been explicitly given the child's process ID. .Sh ERRORS The .Fn wait