Skip to content

Commit

Permalink
kill: kill Win32 processes more gently
Browse files Browse the repository at this point in the history
This change is the equivalent to the change to the Ctrl+C handling we
just made.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Mar 30, 2021
1 parent b1477cb commit 89f6fc3
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions winsup/utils/kill.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ details. */
#include <cygwin/version.h>
#include <getopt.h>
#include <limits.h>
#include <cygwin/exit_process.h>

static char *prog_name;

Expand Down Expand Up @@ -186,10 +187,20 @@ forcekill (pid_t pid, DWORD winpid, int sig, int wait)
return;
}
if (!wait || WaitForSingleObject (h, 200) != WAIT_OBJECT_0)
if (sig && !TerminateProcess (h, sig << 8)
&& WaitForSingleObject (h, 200) != WAIT_OBJECT_0)
fprintf (stderr, "%s: couldn't kill pid %u, %u\n",
prog_name, (unsigned int) dwpid, (unsigned int) GetLastError ());
{
HANDLE cur = GetCurrentProcess (), h2;
/* duplicate handle with access rights required for exit_process_tree() */
if (DuplicateHandle (cur, h, cur, &h2, PROCESS_CREATE_THREAD |
PROCESS_QUERY_INFORMATION |
PROCESS_VM_OPERATION |
PROCESS_VM_WRITE | PROCESS_VM_READ |
PROCESS_TERMINATE, FALSE, 0))
{
CloseHandle(h);
h = h2;
}
exit_process_tree (h2, 128 + sig);
}
CloseHandle (h);
}

Expand Down

0 comments on commit 89f6fc3

Please sign in to comment.