From: Jens Axboe Date: Sat, 17 Feb 2007 05:19:24 +0000 (+0100) Subject: [PATCH] Catch processes/threads that unexpectedly exited X-Git-Tag: fio-1.12~74 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=fab6aa719b7fa80a720f716dc1660165c2f844e9 [PATCH] Catch processes/threads that unexpectedly exited Fio will no longer stall waiting for dead children. Signed-off-by: Jens Axboe --- diff --git a/fio.c b/fio.c index e386f53c..774b160c 100644 --- a/fio.c +++ b/fio.c @@ -793,7 +793,7 @@ static int fork_main(int shmid, int offset) static void reap_threads(int *nr_running, int *t_rate, int *m_rate) { struct thread_data *td; - int i, cputhreads, pending; + int i, cputhreads, pending, status, ret; /* * reap exited threads (TD_EXITED -> TD_REAPED) @@ -807,6 +807,22 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate) if (td->io_ops && td->io_ops->flags & FIO_CPUIO) cputhreads++; + if (td->runstate < TD_EXITED) { + /* + * check if someone quit or got killed in an unusual way + */ + ret = waitpid(td->pid, &status, WNOHANG); + if (ret < 0) + perror("waitpid"); + else if ((ret == td->pid) && WIFSIGNALED(status)) { + int sig = WTERMSIG(status); + + log_err("fio: pid=%d, got signal=%d\n", td->pid, sig); + td_set_runstate(td, TD_REAPED); + goto reaped; + } + } + if (td->runstate != TD_EXITED) { if (td->runstate < TD_RUNNING) pending++; @@ -827,13 +843,16 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate) } else { int status; - waitpid(td->pid, &status, 0); + ret = waitpid(td->pid, &status, 0); + if (ret < 0) + perror("waitpid"); if (WIFEXITED(status) && WEXITSTATUS(status)) { if (!exit_value) exit_value++; } } +reaped: (*nr_running)--; (*m_rate) -= td->ratemin; (*t_rate) -= td->rate;