From f4c0e10ec54eabdd20245492433bec2a968d712e Mon Sep 17 00:00:00 2001 From: fumiama Date: Tue, 20 Apr 2021 18:04:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=9B=E7=A8=8B=E4=BB=A5?= =?UTF-8?q?=E7=9B=91=E6=8E=A7=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=9A=84=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E7=BB=88=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server.c b/server.c index 72c69e9..98f90d5 100644 --- a/server.c +++ b/server.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -344,7 +345,14 @@ void handleAccept(void *p) { } void acceptClient() { - while(1) { + pid_t pid = fork(); + while (pid > 0) { //主进程监控子进程状态,如果子进程异常终止则重启之 + wait(NULL); + puts("Server subprocess exited. Restart..."); + pid = fork(); + } + if(pid < 0) puts("Error when forking a subprocess."); + else while(1) { puts("Ready for accept, waitting..."); int p = 0; while(p < 8 && accept_threads[p] && !pthread_kill(accept_threads[p], 0)) p++;