* 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.
This commit is contained in:
Christopher Faylor 2000-09-13 02:48:39 +00:00
parent 858f524917
commit 6b70b4633c
2 changed files with 24 additions and 6 deletions

View File

@ -1,3 +1,11 @@
Tue Sep 12 22:45:28 2000 Christopher Faylor <cgf@cygnus.com>
* 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 <cgf@cygnus.com>
* Makefile.in: Refine dumper.exe message.

View File

@ -15,10 +15,11 @@ details. */
#include <time.h>
#include <errno.h>
#include <windows.h>
#include <sys/cygwin.h>
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);
}