Reputation: 2564
I am using Poco to create a process in my app. I would like to relaunch the process if the process exits gracefully or it crashes.
Currently it is started as follows:
ProcessHandle ph = Process::launch( "foo.exe", args, 0, &outPipe, 0);
PipeInputStream istr(outPipe);
std::string s;
int c = istr.get();
while (c != -1)
{
s += (char) c; c = istr.get();
}
Graceful exit is handled easily by waiting for the output pile to end as shown above.
How can I handle when the process crashes? I need to handle this on Windows and Linux.
Upvotes: 1
Views: 1451
Reputation: 2409
use the wait() function of the ProcessHandle
object in a different thread. when the wait() call returns, the process has terminated. usually processes that crash have a non-zero exit code, and the wait()
call returns that exit code
Upvotes: 1