1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 14:16:00 +00:00

multicpu1sec-c: handle fork

This commit is contained in:
Steve Schnepp 2015-03-03 23:16:41 +00:00
parent b0e8dcea39
commit 16b017fcd7

View file

@ -1,6 +1,7 @@
/*
* multicpu1sec C plugin
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@ -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());