#pragma once #include #include #include #include using namespace std; class Process { string execname; optional stderrRedirect; pid_t pid = -1; int infd = -1, outfd = -1; int exitStatus = -1; string readBuf; void cleanup(); public: Process(const string_view execname); Process(const Process&) = delete; Process(Process&&) = default; void redirectStderr(const string_view fname); void run(); void stop(); void unStop(); // These return -1 if an error occurred, and the process return value otherwise. // If the process was killed by a signal, (1000 + signal) is returned. int wait(); int waitPoll(); // Also returns -1 if process hasn't finished yet int terminate(); pid_t getPid() const; bool writeLine(const string_view line, bool allowBrokenPipe); optional readLine(); optional readLineTimeout(size_t millis); };