From: Brandon Paupore Date: Fri, 5 Aug 2022 17:57:27 +0000 (-0500) Subject: Add wait for handling SIGBREAK X-Git-Tag: fio-3.32~15^2 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=0dea1f55e9b821a6bcb12e8faaebb8ac91940ad8;p=fio.git Add wait for handling SIGBREAK When closing a command prompt window or terminating it using something like the taskkill command, each child process (such as a running FIO workload) is sent a SIGBREAK signal. Once those child processes have responded to that signal, Windows terminates them if they're still executing. This change has the main thread to wait for others to exit when handling a SIGBREAK signal, such that each job will still have time to wrap-up and give stats before the entire program terminates. Signed-off-by: Brandon Paupore --- diff --git a/backend.c b/backend.c index 5159b60d..4a6a61b8 100644 --- a/backend.c +++ b/backend.c @@ -90,6 +90,25 @@ static void sig_int(int sig) } } +#ifdef WIN32 +static void sig_break(int sig) +{ + struct thread_data *td; + int i; + + sig_int(sig); + + /** + * Windows terminates all job processes on SIGBREAK after the handler + * returns, so give them time to wrap-up and give stats + */ + for_each_td(td, i) { + while (td->runstate < TD_EXITED) + sleep(1); + } +} +#endif + void sig_show_status(int sig) { show_running_run_stats(); @@ -112,7 +131,7 @@ static void set_sig_handlers(void) /* Windows uses SIGBREAK as a quit signal from other applications */ #ifdef WIN32 memset(&act, 0, sizeof(act)); - act.sa_handler = sig_int; + act.sa_handler = sig_break; act.sa_flags = SA_RESTART; sigaction(SIGBREAK, &act, NULL); #endif