From 6b70b4633c100f707689cbba6a1ddd3e4d15e745 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Wed, 13 Sep 2000 02:48:39 +0000 Subject: [PATCH] * kill.cc (main): Change behavior of -f so that it will force the killing of a cygwin process after waiting 2 tenths of a second for it to terminate. (forcekill): Add an extra argument determining whether to wait for the process to exit. --- winsup/utils/ChangeLog | 8 ++++++++ winsup/utils/kill.cc | 22 ++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index f2fbe0044..7f61f5254 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,3 +1,11 @@ +Tue Sep 12 22:45:28 2000 Christopher Faylor + + * kill.cc (main): Change behavior of -f so that it will force the + killing of a cygwin process after waiting 2 tenths of a second for it + to terminate. + (forcekill): Add an extra argument determining whether to wait for the + process to exit. + Sun Sep 10 12:50:02 2000 Christopher Faylor * Makefile.in: Refine dumper.exe message. diff --git a/winsup/utils/kill.cc b/winsup/utils/kill.cc index b0b9da515..7a3be9b35 100644 --- a/winsup/utils/kill.cc +++ b/winsup/utils/kill.cc @@ -15,10 +15,11 @@ details. */ #include #include #include +#include static void usage (void); static int __stdcall getsig (char *); -static void __stdcall forcekill (int, int); +static void __stdcall forcekill (int, int, int); int main (int argc, char **argv) @@ -66,10 +67,15 @@ sig0: printf ("Sending %s(%d) signal to pid %d\n", strsignal (sig), sig, pid); #endif - if (kill (pid, sig)) + if (kill (pid, sig) == 0) + { + if (force) + forcekill (pid, sig, 1); + } + else { if (errno == ESRCH && force && sig != 0) - forcekill (pid, sig); + forcekill (pid, sig, 0); else { char buf[1000]; @@ -107,11 +113,15 @@ getsig (char *in_sig) } static void __stdcall -forcekill (int pid, int sig) +forcekill (int pid, int sig, int wait) { - HANDLE h = OpenProcess (PROCESS_TERMINATE, FALSE, (DWORD) pid); + external_pinfo *p = (external_pinfo *) cygwin_internal (CW_GETPINFO_FULL, pid); + if (!p) + return; + HANDLE h = OpenProcess (PROCESS_TERMINATE, FALSE, (DWORD) p->pid); if (!h) return; - TerminateProcess (h, sig << 8); + if (!wait || WaitForSingleObject (h, 200) != WAIT_OBJECT_0) + TerminateProcess (h, sig << 8); CloseHandle (h); }