diff --git a/plugins/system/multicpu1sec/multicpu1sec-c.c b/plugins/system/multicpu1sec/multicpu1sec-c.c index fd11c359..477d57c0 100644 --- a/plugins/system/multicpu1sec/multicpu1sec-c.c +++ b/plugins/system/multicpu1sec/multicpu1sec-c.c @@ -1,6 +1,7 @@ /* * multicpu1sec C plugin */ +#include #include #include #include @@ -83,6 +84,21 @@ time_t wait_until_next_second() { int acquire() { + /* fork ourselves if not asked otherwise */ + char* no_fork = getenv("no_fork"); + if (! no_fork || strcmp("1", no_fork)) { + if (fork()) return; + // we are the child, complete the daemonization + + /* Close standard IO */ + fclose(stdin); + fclose(stdout); + fclose(stderr); + + /* create new session and process group */ + setsid(); + } + /* write the pid */ FILE* pid_file = fopen(pid_filename, "w"); fprintf(pid_file, "%d\n", getpid());