From nobody Mon Aug 3 11:38:45 2026 X-Original-To: dev-commits-src-branches@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 4hDF7B5h7wz6nCKW for ; Mon, 03 Aug 2026 11:38:46 +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 4hDF795ZPHz3Rkj for ; Mon, 03 Aug 2026 11:38:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785757125; 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=IpoMp02C00IdIT6aw3Nf/xvkABEt/VRqHb7QeQ2W6Yg=; b=YK+gXTFYX+Ak3jTj45z7dazpn0bV7NSEWOBZZOB6vEshfiICuUVbXhPKEmiPqnWbCpT/Im nHSBApMcBJ7urrW9w92VQs5npjbe9DM8fcsg5UMZ/O+3zDLsgJl5UzfxN5PIkoWX0TqIO0 XOK2/AUxb3p3wh4SyFHT0SDvjfWr/4y+QDySAUY0Sr9qP0WqkLgSznmYd3Gpkke7Nx8xpI RDUwfJ3vloW9l2sEvLMkF8OvzGtNRfJ8fU+/St5TSUPT+8lIOsERCQXp8sWwDQlPBRaV84 fi7Jc6FG7e045WYwnW3Z61B3s/44t1KCN/RP7MwokJT9xKcyXNtRwtvRLv3Ttw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785757125; a=rsa-sha256; cv=none; b=AzZR0zDpq07yTdsBdM9cSm5FJ1BgAuAXPcO0SjiFnBj4Ano+l23IMRPzvkeho/SZ1lSwpJ OVWrLDl3Xyl4vgHU/M46gtBMQfX5IBO9u0e02OwBtOjwiqEswCpfyfZqdpF77Cf9TI/27I riTfpWIhz0EkIv+lC2GsDBDohJfOOygfdhe/Ze0LyN0dkGvpOSAMsmbV/Paq/YKfKfmz5S uwiA2gluHCwEJzT1glo8L+DPUiw/4dujiay/3BxGdd+juN08wZS+UeZLObqWiPk4aiSYfz mLHg5Hb9g5/0yGjtvO5cowvK3aYRdXEPm1V5wS0D6KLQW9kidGzBVcNY+HoNPA== 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=1785757125; 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=IpoMp02C00IdIT6aw3Nf/xvkABEt/VRqHb7QeQ2W6Yg=; b=T6xRUcWolK9Sbn2kzdhtBwqqTQubNrwXSeGN9e2qpVJn2pr5Bb6eo0gQr54dBAGPjZSNtF RwxeLzc9/GVl0xS6+EawxPmzzvwW6AOX0sp8eSv1DDg9Ar6fCjV1V8QajZwkvdTZyzNUgG aT5jAkItGOf4GBJcMvuDyiv0L8CjKmv/i2jlFAdEti1QIlzQ/Y8cKzwm3encfxjMtofqR6 eVoue3kuzP7ySus0l99QHGZio8PKw9txvQdWTE20gFoSkuEspX6eRCtlY90nZpeNLAgRIF hLChGO65cKtjLsfdf/KQRq5WuNNAjoUKy3sY+wt5rGtLaqW2VST5zZUIpPrHqw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hDF794XV1zypt for ; Mon, 03 Aug 2026 11:38:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1be73 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 03 Aug 2026 11:38:45 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: ae3c852dfbd8 - stable/14 - pwait: Optionally wait until process is reaped List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: ae3c852dfbd883af905f38a6a1c5ebae0224135b Auto-Submitted: auto-generated Date: Mon, 03 Aug 2026 11:38:45 +0000 Message-Id: <6a707dc5.1be73.20bce329@gitrepo.freebsd.org> The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=ae3c852dfbd883af905f38a6a1c5ebae0224135b commit ae3c852dfbd883af905f38a6a1c5ebae0224135b Author: Dag-Erling Smørgrav AuthorDate: 2026-07-27 10:15:31 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-08-03 11:32:13 +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 (cherry picked from commit c8f5e6819d4d81906c4a1641b5c9f02d8730481c) --- 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 c61f6854358b..a80c04a1e688 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 6e9e634b4526..385278dbc991 100644 --- a/bin/pwait/pwait.c +++ b/bin/pwait/pwait.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -67,7 +68,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); } @@ -85,16 +86,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; @@ -102,6 +104,9 @@ main(int argc, char *argv[]) case 'p': pflag = true; break; + case 'r': + rflag = true; + break; case 't': tflag = true; errno = 0; @@ -164,6 +169,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 */ @@ -189,7 +197,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()"); @@ -229,9 +237,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", @@ -243,13 +253,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) {