From e197ae6fae73719266fd4747f499cd6106fbff4e Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 8 Oct 2020 21:24:00 +0300 Subject: Add process::term() and implement process::kill() on Windows --- libbutl/process.mxx | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'libbutl/process.mxx') diff --git a/libbutl/process.mxx b/libbutl/process.mxx index 54abdec..9106549 100644 --- a/libbutl/process.mxx +++ b/libbutl/process.mxx @@ -360,27 +360,37 @@ LIBBUTL_MODEXPORT namespace butl // duration. Return the same result as wait() if the process has // terminated in this timeframe and nullopt otherwise. // - // Note: not yet implemented on Windows. - // template optional timed_wait (const std::chrono::duration&); - // Terminate the process. + // Note that the destructor will wait for the process but will ignore + // any errors and the exit status. + // + ~process () {if (handle != 0) wait (true);} + + // Process termination. // - // On POSIX send SIGKILL to the process and wait until it terminates. The - // process exit information is available after the call returns. Noop for - // an already terminated process. + + // Send SIGKILL to the process on POSIX and call TerminateProcess() with + // DBG_TERMINATE_PROCESS exit code on Windows. Noop for an already + // terminated process. + // + // Note that if the process is killed, it terminates as if it has called + // abort() (functions registered with atexit() are not called, etc). // - // Note: not yet implemented on Windows. + // Also note that on Windows calling this function for a terminating + // process results in the EPERM process_error exception. // void kill (); - // Note that the destructor will wait for the process but will ignore - // any errors and the exit status. + // Send SIGTERM to the process on POSIX and call kill() on Windows (where + // there is no general way to terminate a console process gracefully). + // Noop for an already terminated process. // - ~process () {if (handle != 0) wait (true);} + void + term (); // Moveable-only type. // -- cgit v1.1