summaryrefslogtreecommitdiff
path: root/process.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'process.cpp')
-rw-r--r--process.cpp6
1 files changed, 6 insertions, 0 deletions
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;
}
}