diff --git a/build/main.c b/build/main.c
index d5fec663ee646b275a093ab723d0e121197adc6d..c6c36afdf5188370cb0c76c26233d5b29a53c087 100644
--- a/build/main.c
+++ b/build/main.c
@@ -77,7 +77,15 @@ static struct mg_context *ctx;      // Set by start_mongoose()
 #endif /* !CONFIG_FILE */
 
 static void WINCDECL signal_handler(int sig_num) {
-  exit_flag = sig_num;
+#if !defined(_WIN32)
+  // Do not do the trick with ignoring SIGCHLD, cause not all OSes (e.g. QNX)
+  // reap zombies if SIGCHLD is ignored. On QNX, for example, waitpid()
+  // fails if SIGCHLD is ignored, making system() non-functional.
+  if (sig_num == SIGCHLD) {
+    do {} while (waitpid(-1, &sig_num, WNOHANG) > 0);
+  } else
+#endif
+  { exit_flag = sig_num; }
 }
 
 static void die(const char *fmt, ...) {
@@ -375,11 +383,6 @@ static void start_mongoose(int argc, char *argv[]) {
   signal(SIGTERM, signal_handler);
   signal(SIGINT, signal_handler);
 
-#if !defined(_WIN32)
-  // Also ignoring SIGCHLD to let the OS to reap zombies properly.
-  (void) signal(SIGCHLD, SIG_IGN);
-#endif
-
   // Start Mongoose
   memset(&callbacks, 0, sizeof(callbacks));
   callbacks.log_message = &log_message;