From 2c6f4368586d42b60d62bfe52579b1c881b30760 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Tue, 29 Oct 2019 15:52:53 +0100 Subject: [PATCH] Fix shmmonitor daemonization --- fairmq/shmem/runMonitor.cxx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/fairmq/shmem/runMonitor.cxx b/fairmq/shmem/runMonitor.cxx index 0bfe41ed..19fccdc9 100644 --- a/fairmq/shmem/runMonitor.cxx +++ b/fairmq/shmem/runMonitor.cxx @@ -26,19 +26,25 @@ using namespace fair::mq::shmem; static void daemonize() { // already a daemon? - // if (getppid() == 1) return; + if (getppid() == 1) { + return; + } - // Fork off the parent process - // pid_t pid = fork(); - // if (pid < 0) exit(1); + // Fork + pid_t pid = fork(); + if (pid < 0) { + exit(1); + } // If we got a good PID, then we can exit the parent process. - // if (pid > 0) exit(0); + if (pid > 0) { + exit(0); + } // Change the file mode mask umask(0); - // Create a new SID for the child process + // Create a new session with the calling process as its leader. if (setsid() < 0) { exit(1); }