From 57767b8121f605b7e89e7a52c6d71be614399469 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Wed, 19 Mar 2014 23:01:55 -0400 Subject: don't get blocked on zombies --- mteval/external_scorer.cc | 7 +++++++ mteval/ns_ext.cc | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'mteval') diff --git a/mteval/external_scorer.cc b/mteval/external_scorer.cc index f1b3ed6e..c7c3de1a 100644 --- a/mteval/external_scorer.cc +++ b/mteval/external_scorer.cc @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -15,6 +16,7 @@ using namespace std; extern const char* meteor_jar_path; +extern void metric_child_signal_handler(int); map > ScoreServerManager::servers_; @@ -46,6 +48,11 @@ ScoreServer* ScoreServerManager::Instance(const string& score_type) { } ScoreServer::ScoreServer(const string& cmd) { + static bool need_init = true; + if (need_init) { + need_init = false; + signal(SIGCHLD, metric_child_signal_handler); + } cerr << "Invoking " << cmd << " ..." << endl; if (pipe(p2c) < 0) { perror("pipe"); exit(1); } if (pipe(c2p) < 0) { perror("pipe"); exit(1); } diff --git a/mteval/ns_ext.cc b/mteval/ns_ext.cc index 1e7e2bc1..9d2c75c6 100644 --- a/mteval/ns_ext.cc +++ b/mteval/ns_ext.cc @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include #include @@ -13,6 +15,14 @@ using namespace std; +void metric_child_signal_handler(int signo) { + int status = 0; + cerr << "Received SIGCHLD(" << signo << ") ... aborting.\n"; + // reap zombies + while (waitpid(-1, &status, WNOHANG) > 0) {} + abort(); +} + struct NScoreServer { NScoreServer(const std::string& cmd); ~NScoreServer(); @@ -27,6 +37,12 @@ struct NScoreServer { }; NScoreServer::NScoreServer(const string& cmd) { + static bool need_init = true; + if (need_init) { + need_init = false; + signal(SIGCHLD, metric_child_signal_handler); + } + cerr << "Invoking " << cmd << " ..." << endl; if (pipe(p2c) < 0) { perror("pipe"); exit(1); } if (pipe(c2p) < 0) { perror("pipe"); exit(1); } -- cgit v1.2.3