Add wait for handling SIGBREAK
authorBrandon Paupore <brandon.paupore@wdc.com>
Fri, 5 Aug 2022 17:57:27 +0000 (12:57 -0500)
committerBrandon Paupore <brandon.paupore@wdc.com>
Tue, 23 Aug 2022 14:24:26 +0000 (09:24 -0500)
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 <brandon.paupore@wdc.com>
backend.c

index 5159b60ddfe5836765f73a5bb0cbd1f416f4f0c4..4a6a61b83580ac3edc24a4a176cd2edcafb62bb3 100644 (file)
--- 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