Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FDBMonitor will only kill its entire process group on exit if it star… #826

Merged
merged 4 commits into from
Nov 12, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions fdbmonitor/fdbmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,13 +635,15 @@ bool argv_equal(const char** a1, const char** a2)
return true;
}

void kill_process(uint64_t id) {
void kill_process(uint64_t id, bool wait = true) {
pid_t pid = id_pid[id];

log_msg(SevInfo, "Killing process %d\n", pid);

kill(pid, SIGTERM);
waitpid(pid, NULL, 0);
if(wait) {
waitpid(pid, NULL, 0);
}

pid_id.erase(pid);
id_pid.erase(id);
Expand Down Expand Up @@ -1367,8 +1369,16 @@ int main(int argc, char** argv) {
signal(SIGCHLD, SIG_IGN);
sigprocmask(SIG_SETMASK, &normal_mask, NULL);

/* Send SIGHUP to all child processes */
kill(0, SIGHUP);
/* If daemonized, setsid() was called earlier so we can just kill our entire new process group */
if(daemonize) {
kill(0, SIGHUP);
}
else {
/* Otherwise kill each process individually but don't wait on them yet */
for(auto i : id_pid) {
kill_process(i.first, false);
}
}

/* Wait for all child processes (says POSIX.1-2001) */
/* POSIX.1-2001 specifies that if the disposition of SIGCHLD is set to SIG_IGN, then children that terminate do not become zombies and a call to wait()
Expand Down