From 41681a5eb7d1e83f1f0f48c1c4ca5b51270f12c4 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Tue, 1 Jun 2021 15:34:18 +0800 Subject: [PATCH] process_stop more gracefully (kill -9 on timeout) --- HISTORY | 3 +++ src/process_ctrl.c | 42 +++++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/HISTORY b/HISTORY index d50e084..b699faa 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,7 @@ +Version 1.52 2021-06-01 + * process_stop more gracefully (kill -9 on timeout) + Version 1.51 2021-05-27 * fast_mblock.[hc]: support batch alloc and batch free * uniq_skiplist.[hc]: init function add parameter: allocator_use_lock diff --git a/src/process_ctrl.c b/src/process_ctrl.c index 31ec4b7..c16871e 100644 --- a/src/process_ctrl.c +++ b/src/process_ctrl.c @@ -114,39 +114,47 @@ static int do_stop(const char *pidFilename, const bool bShowError, pid_t *pid) int process_stop(const char *pidFilename) { +#define MAX_WAIT_COUNT 300 pid_t pid; int result; + int sig; + int i; - result = do_stop(pidFilename, true, &pid); - if (result != 0) { + if ((result=do_stop(pidFilename, true, &pid)) != 0) { return result; } fprintf(stderr, "waiting for pid [%d] exit ...\n", (int)pid); - do { - sleep(1); - } while (kill(pid, SIGTERM) == 0); - fprintf(stderr, "pid [%d] exit.\n", (int)pid); + for (i=0; i