From 2ebdcf82eebec230549b64dc740ea604c7772049 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sun, 30 Dec 2018 20:46:49 -0600 Subject: [PATCH] Do not use up the ~WNOHANG waitpid call on completed processes This is the more correct fix for #5447, as regardless of which process in the job (be it the first or the last) finished first, once we have waited on a process without ~WNOHANG we don't do that for any subsequent processes in the job. It is also a waste to call into the kernel to wait for a process we already know is completed! --- src/proc.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/proc.cpp b/src/proc.cpp index a5895c7cd..7f5f37b9d 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -478,6 +478,11 @@ static bool process_mark_finished_children(bool block_on_fg) { break; } assert((*process)->pid != INVALID_PID && "Waiting by process on an invalid PID!"); + if ((*process)->completed) { + // This process has already been waited on to completion + continue; + } + if ((options & WNOHANG) == 0) { debug(4, "Waiting on individual process %d", (*process)->pid); } else {