From nobody Mon Jul 27 10:17:17 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 4h7vfQ4lWwz6mlMh for ; Mon, 27 Jul 2026 10:17:18 +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 4h7vfQ25Hpz3L3k for ; Mon, 27 Jul 2026 10:17:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785147438; 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=YSue9LIdSAxFDZnV+s9c3d0wGRy5B7qNeNitnI4Olwg=; b=YsWjvYNssjiDqoV0Y+qHuDZcdQsc2ob0kicVagIJwnCxUuMou6MzTOPrI8Q/D9c39w/yrZ DbYBpGvlURH5W3S5VgOmFjLzTafPX0vt03zqBdzadrJDn5IUiONu2ICVxXzYX0OX0X6ILE VwptG5Ixoa1a5Ruj3U7tHUNm7TX1I29FmaDrvmGziO0v0dVGEnUvdOdi5DRsWJxsYCTZCi hdldlks4UccLwTqr5C9LAvjitSw+iz49NzAGbrUv0NLoln+rl571xHVKv5FzJ8p3U6IEf8 d5CVg1cK/tVIIvaj+ees6kFHaA2xQ1tLo+zv5Mw/yYdwyf0zx6dqO/L9dVHmuA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785147438; a=rsa-sha256; cv=none; b=oXnlNo1BEsFRoCgr4cD8Z4nI+H1LVJYfBLepXY1+gGy+mgrCF9+dXa4H/kIsM5nVDu4DAr 5aqT6XX685/xSv8PWqBqxDy5YpgRUwPOVtC1hy1pPZHUMtKkkelIc1oJTYhXOC297vY7xT pKJ8iSstf8TQywctbw+JocMa9AQFYIs1N8EhKNy6tTETvrK4XqKp0YuU05qqA4PHPXRch5 Qk1X0FdI1ofz330mkgib5fdo90xr2KZ7ub66OYTR+GxCb9Hpnk5G862FmgvQQwRD8ROKL5 joiLfDHSuFPqm4Woried717bjxEfsEnXXaTco1DSfg/+N+kRdzDvJZc2Wsi0nA== 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=1785147438; 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=YSue9LIdSAxFDZnV+s9c3d0wGRy5B7qNeNitnI4Olwg=; b=l6zZ9vGnQHYrBKTbXrLWf4Vthgs5mGeGAU7y6vreZ9GYnWef7lSiEyLjqnR+IfN92aFSe2 ziHh21sGxfM76RbOnf3/FrKD7TUcoYjfa7/DojlgBDHFsMvldrB4fo/zChma2kwEY2N0Au djSTURtyzYdxVKjGnTMkXbgki+vdcCJMC98YtxAaIn3RzPNFRWX26CwbLj8vM8uEo7UKZo peBQR03BF+AWal6GudrhRzOKI6p0RPPejP3tWV9K1YLhWVoHqH9/paoac4ec8423EgNOYQ 14iNXnz06DicubvIGzeyyO1Wuw6/neFngiwCVj+/g139x1o8ME2myn8y9RCjsQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4h7vfQ0Fffz14P4 for ; Mon, 27 Jul 2026 10:17:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1f998 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 27 Jul 2026 10:17:17 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: c8f5e6819d4d - main - pwait: Optionally wait until process is reaped 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: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c8f5e6819d4d81906c4a1641b5c9f02d8730481c Auto-Submitted: auto-generated Date: Mon, 27 Jul 2026 10:17:17 +0000 Message-Id: <6a67302d.1f998.2405cd66@gitrepo.freebsd.org> The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=c8f5e6819d4d81906c4a1641b5c9f02d8730481c commit c8f5e6819d4d81906c4a1641b5c9f02d8730481c Author: Dag-Erling Smørgrav AuthorDate: 2026-07-27 10:15:31 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-07-27 10:15:31 +0000 pwait: Optionally wait until process is reaped If the new -r option is specified, wait until the target process not only terminates but is reaped. MFC after: 1 week Sponsored by: Klara, Inc. Sponsored by: NetApp, Inc. Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D58314 --- bin/pwait/pwait.1 | 17 ++++++++++++++--- bin/pwait/pwait.c | 41 +++++++++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/bin/pwait/pwait.1 b/bin/pwait/pwait.1 index d92b829b1d6a..2776d3439a31 100644 --- a/bin/pwait/pwait.1 +++ b/bin/pwait/pwait.1 @@ -30,7 +30,7 @@ .\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY .\" OF SUCH DAMAGE. .\" -.Dd October 22, 2025 +.Dd July 22, 2026 .Dt PWAIT 1 .Os .Sh NAME @@ -39,7 +39,7 @@ .Sh SYNOPSIS .Nm .Op Fl t Ar duration -.Op Fl opv +.Op Fl oprv .Ar pid \&... .Sh DESCRIPTION @@ -53,6 +53,17 @@ The following option is available: Exit when any of the given processes has terminated. .It Fl p On exit, print a list of processes that have not terminated. +.It Fl r +Do not exit until target processes have not only terminated, but been +reaped by a call to the +.Xr wait 2 +family of functions. +Without this flag, target processes may still exist as zombies when +.Nm +exits. +Beware of deadlocks if a target process's reaper (usually its parent) +is directly or indirectly blocked by +.Nm . .It Fl t Ar duration If any process is still running after .Ar duration , @@ -127,8 +138,8 @@ $ sleep 30 & sleep 40 & [2] 1675 $ pwait -v -t 60 1674 1675 1674: exited with status 0. -1675: exited with status 0. [1]- Done sleep 30 +1675: exited with status 0. [2]+ Done sleep 40 $ echo $? 0 diff --git a/bin/pwait/pwait.c b/bin/pwait/pwait.c index 7f134036f1b9..36c6644f5474 100644 --- a/bin/pwait/pwait.c +++ b/bin/pwait/pwait.c @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -68,7 +69,7 @@ RB_GENERATE_STATIC(pidtree, pid, entry, pidcmp); static void usage(void) { - fprintf(stderr, "usage: pwait [-t timeout] [-opv] pid ...\n"); + fprintf(stderr, "usage: pwait [-oprv] [-t timeout] pid ...\n"); exit(EX_USAGE); } @@ -86,16 +87,17 @@ main(int argc, char *argv[]) size_t sz; long pid; pid_t mypid; - int i, kq, n, ndone, nleft, opt, pid_max, ret, status; - bool oflag, pflag, tflag, verbose; + int i, kq, n, ndone, nleft, notes, opt, pid_max, ret, status; + bool oflag, pflag, rflag, tflag, verbose; oflag = false; pflag = false; + rflag = false; tflag = false; verbose = false; memset(&itv, 0, sizeof(itv)); - while ((opt = getopt(argc, argv, "opt:v")) != -1) { + while ((opt = getopt(argc, argv, "oprt:v")) != -1) { switch (opt) { case 'o': oflag = true; @@ -103,6 +105,9 @@ main(int argc, char *argv[]) case 'p': pflag = true; break; + case 'r': + rflag = true; + break; case 't': tflag = true; errno = 0; @@ -165,6 +170,9 @@ main(int argc, char *argv[]) } ndone = nleft = 0; mypid = getpid(); + notes = rflag ? NOTE_REAP : NOTE_EXIT; + if (verbose) + notes |= NOTE_EXIT; for (n = 0; n < argc; n++) { s = argv[n]; /* Undocumented Solaris compat */ @@ -190,7 +198,7 @@ main(int argc, char *argv[]) free(p); continue; } - EV_SET(e + nleft, pid, EVFILT_PROC, EV_ADD, NOTE_EXIT, 0, NULL); + EV_SET(e + nleft, pid, EVFILT_PROC, EV_ADD, notes, 0, NULL); if (kevent(kq, e + nleft, 1, NULL, 0, NULL) == -1) { if (errno != ESRCH) err(EX_OSERR, "kevent()"); @@ -230,9 +238,11 @@ main(int argc, char *argv[]) printf("timeout\n"); } ret = 124; + continue; } + assert(e[i].filter == EVFILT_PROC); pid = e[i].ident; - if (verbose) { + if ((e[i].fflags & NOTE_EXIT) && verbose) { status = e[i].data; if (WIFEXITED(status)) { printf("%ld: exited with status %d.\n", @@ -244,13 +254,20 @@ main(int argc, char *argv[]) printf("%ld: terminated.\n", pid); } } - k.pid = pid; - if ((p = RB_FIND(pidtree, &pids, &k)) != NULL) { - RB_REMOVE(pidtree, &pids, p); - free(p); - ndone++; + if ((e[i].fflags & NOTE_REAP) && verbose) { + printf("%ld: reaped.\n", pid); + } + if ((e[i].fflags & NOTE_REAP) || + (!rflag && (e[i].fflags & NOTE_EXIT))) { + /* this process is done */ + k.pid = pid; + if ((p = RB_FIND(pidtree, &pids, &k)) != NULL) { + RB_REMOVE(pidtree, &pids, p); + free(p); + ndone++; + } + --nleft; } - --nleft; } } if (pflag) {