--- a/process.c
+++ b/process.c
@@ -38,18 +38,20 @@
 #include <signal.h>
 #include <sys/wait.h>
 
+#include "upnpglobalvars.h"
 #include "process.h"
 #include "config.h"
 #include "log.h"
 
-static const int max_number_of_children = 5;
 static int number_of_children = 0;
 
 pid_t
 process_fork(void)
 {
-	if (number_of_children >= max_number_of_children)
+	if (number_of_children >= runtime_vars.max_connections)
 	{
+		DPRINTF(E_WARN, L_GENERAL, "Exceeded max connections [%d], not forking\n",
+			runtime_vars.max_connections);
 		errno = EAGAIN;
 		return -1;
 	}
@@ -63,8 +65,21 @@
 void
 process_handle_child_termination(int signal)
 {
-	waitpid(-1, NULL, WNOHANG);
-	--number_of_children;
+	pid_t pid;
+
+	while ((pid = waitpid(-1, NULL, WNOHANG)))
+	{
+		if (pid == -1)
+		{
+			if (errno == EINTR)
+				continue;
+			else
+				break;
+		}
+		else if (pid == 0)
+			break;
+		--number_of_children;
+	}
 }
 
 int