diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2018-09-18 00:06:29 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2018-09-18 00:07:01 +0200 |
commit | 0624562e3e1ae24fd1df66e3e38afca7b0f1c70f (patch) | |
tree | 89efc54b78135f5625fd69a03b89dee8b7d78353 /process.h | |
parent | 44182a1be82d5e5df6f7b1a3c85dd7386b397007 (diff) |
Fix bugs
- Cleanup open file descriptors properly
- Use cout, not cerr
- Better error logging, including when a program is killed by a signal
Diffstat (limited to 'process.h')
-rw-r--r-- | process.h | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -14,8 +14,12 @@ class Process { 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; @@ -24,10 +28,13 @@ public: void redirectStderr(const string_view fname); void run(); - void wait(); void stop(); void unStop(); - void terminate(); + // 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; |