Separate process wait and close

On Linux, waitpid() both waits for the process to terminate and reaps it
(closes its handle). On Windows, these actions are separated into
WaitForSingleObject() and CloseHandle().

Expose these actions separately, so that it is possible to send a signal
to a process while waiting for its termination without race condition.

This allows to wait for server termination normally, but kill the
process without race condition if it is not terminated after some delay.
This commit is contained in:
Romain Vimont
2021-01-03 17:06:08 +01:00
parent 821c175730
commit d580ee30f1
4 changed files with 64 additions and 13 deletions

View File

@@ -46,10 +46,20 @@ process_execute(const char *const argv[], process_t *process);
bool
process_terminate(process_t pid);
// wait and close the process
// wait and close the process (like waitpid())
bool
process_wait(process_t pid, exit_code_t *exit_code);
// wait (but does not close) the process (waitid() with WNOWAIT)
bool
process_wait_noclose(process_t pid, exit_code_t *exit_code);
// close the process
//
// Semantically, process_wait = process_wait_noclose + process_close.
void
process_close(process_t pid);
// convenience function to wait for a successful process execution
// automatically log process errors with the provided process name
bool