diff options
-rw-r--r-- | main.cpp | 3 | ||||
-rw-r--r-- | process.cpp | 6 |
2 files changed, 6 insertions, 3 deletions
@@ -311,9 +311,6 @@ match_done: if (success) usleep(10000); procs[i].terminate(); } - for (int i = 0; i < 2; i++) { - procs[i].wait(); - } gMultiLog.append(logId, mres.describe(p1, p2)); gMultiLog.complete(logId); diff --git a/process.cpp b/process.cpp index d3ceb28..cab5484 100644 --- a/process.cpp +++ b/process.cpp @@ -64,6 +64,7 @@ void Process::run() { } void Process::wait() { + if (pid == -1) return; while (true) { int status; if (waitpid(pid, &status, 0) < 0) { @@ -88,6 +89,8 @@ void Process::unStop() { } bool Process::writeLine(const string_view line) { + if (pid == -1) return false; + string str; str.reserve(line.size() + 1); str += line; @@ -108,6 +111,8 @@ bool Process::writeLine(const string_view line) { } optional<string> Process::readLine() { + if (pid == -1) return nullopt; + size_t idx = readBuf.find('\n'); if (idx != string::npos) { string res = readBuf.substr(0, idx); @@ -144,6 +149,7 @@ void Process::terminate() { // SIGKILL if necessary if (pid != -1) { kill(pid, SIGKILL); // force kill + wait(); pid = -1; } } |