While waiting for a boost::process::child
, how can you know if it exited "gracefully or not"?
Let's say I create a processus:
boost::process::child child( "myprg.exe", "5000" );
child.wait();
int res = child.exit_code();
Where myprg.exe is:
int main( int argc, char* argv[] )
{
if ( argc == 2 )
{
boost::this_thread::sleep( boost::posix_time::milliseconds( atoi( argv[1] ) ) );
return 1;
}
return 0;
}
Note: This a MCVE that makes no sense, I agree main should return 0 if successfull.
I see that if someone kills the process while it waits (using child.terminate
for instance or Windows Process Manager), child.exit_code()
will return 1.
So, in the end, when child.exit_code()
is 1, how can I know if this is the value returned by the process's main entry function or if the process was killed?
Is it guaranteed that 1 will mean process was killed? Then program should not return 1 and keep this exit code to identify the specific situation where it was killed and did not exit cleanly?
If not, does boost::process
API provide something to know if process ended up cleanly or was killed?