When we free and kill a process also wait for it

Merged
#34 · Created  · Last updated

Merged pull request

Merged in guillemj/monit (pull request #34)

04a7525·Author: ·Closed by: ·2016-03-18

Description

Otherwise we leave zombies laying around, which are a sanitary hazard at best, and very confusing at worst, because it is not clear whether there is a problem with the process or with the monitoring itself. Not reaping zombies properly might also run afoul of system limits.

This happens commonly when timeouts trigger, as the process structure is freed but nothing waits for the pid, and then the pid is lost.

Here's a small reproducer:

zombie.c:

#include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() { pid_t pid; pid = fork(); if (pid < 0) { fprintf(stderr, "error forking: %m\n"); exit(2); } else if (pid == 0) _exit(0); } else { FILE *fp = fopen("/var/run/zombie.pid", "w+"); if (fp == NULL) exit(1); fprintf(fp, "%d\n", pid); fclose(fp); sleep(120); exit(0); } return 0; }

/etc/monit/monitrc.d/zombie:

check process zombie with pidfile /var/run/zombie.pid start program = "/root/zombie" with timeout 2 seconds mode manual

0 attachments

0 comments

Loading commits...