Skip to content

Commit f4a52b9

Browse files
committed
squash! kill: Handle Win32 console processes' children, too
kill: kill Win32 processes more gently This change is the equivalent to the change to the Ctrl+C handling we just made. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent e9cb332 commit f4a52b9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

winsup/utils/kill.cc

+16-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ details. */
1717
#include <cygwin/version.h>
1818
#include <getopt.h>
1919
#include <limits.h>
20+
#include <cygwin/exit_process.h>
2021

2122
static char *prog_name;
2223

@@ -173,7 +174,21 @@ forcekill (int pid, int sig, int wait)
173174
if (!wait || WaitForSingleObject (h, 200) != WAIT_OBJECT_0)
174175
{
175176
if (sig == SIGINT || sig == SIGTERM)
176-
kill_process_tree (dwpid, sig);
177+
{
178+
HANDLE cur = GetCurrentProcess (), h2;
179+
/* duplicate handle with access rights required for exit_process() */
180+
if (DuplicateHandle (cur, h, cur, &h2, PROCESS_CREATE_THREAD |
181+
PROCESS_QUERY_INFORMATION |
182+
PROCESS_VM_OPERATION |
183+
PROCESS_VM_WRITE | PROCESS_VM_READ |
184+
PROCESS_TERMINATE, FALSE, 0))
185+
{
186+
exit_process (h2, 128 + sig);
187+
CloseHandle (h2);
188+
}
189+
else
190+
terminate_process_tree(h, 128 + sig);
191+
}
177192
else if (sig && !TerminateProcess (h, sig << 8)
178193
&& WaitForSingleObject (h, 200) != WAIT_OBJECT_0)
179194
fprintf (stderr, "%s: couldn't kill pid %u, %u\n",

0 commit comments

Comments
 (0)