diff --git a/src/proc.cpp b/src/proc.cpp index 2a2a026f2..6bdfe15ac 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -248,6 +248,8 @@ static void handle_child_status(process_t *proc, proc_status_t status) { proc->status = status; if (status.stopped()) { proc->stopped = true; + } else if (status.continued()) { + proc->stopped = false; } else { proc->completed = true; } @@ -417,13 +419,20 @@ static void process_mark_finished_children(parser_t &parser, bool block_ok) { } else if (proc->pid > 0) { // Try reaping an external process. int status = -1; - auto pid = waitpid(proc->pid, &status, WNOHANG | WUNTRACED); + auto pid = waitpid(proc->pid, &status, WNOHANG | WUNTRACED | WCONTINUED); if (pid > 0) { assert(pid == proc->pid && "Unexpcted waitpid() return"); handle_child_status(proc.get(), proc_status_t::from_waitpid(status)); - FLOGF(proc_reap_external, - "Reaped external process '%ls' (pid %d, status %d)", - proc->argv0(), pid, proc->status.status_value()); + if (proc->status.normal_exited() || proc->status.signal_exited()) { + FLOGF(proc_reap_external, + "Reaped external process '%ls' (pid %d, status %d)", + proc->argv0(), pid, proc->status.status_value()); + } else { + assert(proc->status.stopped() || proc->status.continued()); + FLOGF(proc_reap_external, + "External process '%ls' (pid %d, %s)", + proc->argv0(), pid, proc->status.stopped() ? "stopped" : "continued"); + } } } else { assert(0 && "Don't know how to reap this process"); diff --git a/src/proc.h b/src/proc.h index 3a4a7395b..658b49933 100644 --- a/src/proc.h +++ b/src/proc.h @@ -82,6 +82,9 @@ class proc_status_t { /// \return if we are stopped (as in SIGSTOP). bool stopped() const { return WIFSTOPPED(status_); } + /// \return if we are continued (as in SIGCONT). + bool continued() const { return WIFCONTINUED(status_); } + /// \return if we exited normally (not a signal). bool normal_exited() const { return WIFEXITED(status_); } diff --git a/tests/wait.expect b/tests/wait.expect index 354eb8329..ab8362f1b 100644 --- a/tests/wait.expect +++ b/tests/wait.expect @@ -58,6 +58,9 @@ expect_prompt send_line "jobs" expect_prompt "jobs: There are no jobs" {} unmatched { puts stderr $error_msg } +send_line "sleep .3 &; kill -STOP %1; kill -CONT %1; jobs | string match -r running; wait" +expect_prompt "running" {} unmatched { puts stderr "continued job should be running: Fail" } + # return immediately when no jobs set error_msg "return immediately when no jobs: Fail"