diff options
author | Christopher Faylor <me@cgf.cx> | 2000-07-29 16:26:37 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2000-07-29 16:26:37 +0000 |
commit | cc631726d3e1609570170564e442bf735b906448 (patch) | |
tree | b4d9bef98c0e3bb59194e02c271e908023f1b3a2 /winsup/utils/kill.cc | |
parent | 84c7d4093270dc07de4531ab6648a12daaff77c3 (diff) | |
download | newlib-cc631726d3e1609570170564e442bf735b906448.zip newlib-cc631726d3e1609570170564e442bf735b906448.tar.gz newlib-cc631726d3e1609570170564e442bf735b906448.tar.bz2 |
* kill.cc (main): Add '-f' option to force termination of a process.
(forcekill): New function.
* ps.cc (main): Add '-W' option to list Windows pids as well as Cygwin pids.
(dummyprocessmodules): New function.
(GetModuleFileNameEx95): New function.
(init_win): New function.
(to_time_t): New function.
Diffstat (limited to 'winsup/utils/kill.cc')
-rw-r--r-- | winsup/utils/kill.cc | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/winsup/utils/kill.cc b/winsup/utils/kill.cc index 6118878..a7913e4 100644 --- a/winsup/utils/kill.cc +++ b/winsup/utils/kill.cc @@ -1,6 +1,6 @@ /* kill.cc - Copyright 1996, 1997, 1998 Cygnus Solutions. + Copyright 1996, 1997, 1998, 1999, 2000 Red Hat, Inc. This file is part of Cygwin. @@ -13,50 +13,72 @@ details. */ #include <signal.h> #include <string.h> #include <time.h> +#include <errno.h> +#include <windows.h> static void usage (void); -static int getsig (char *); -int a = _timezone; +static int __stdcall getsig (char *); +static void __stdcall forcekill (int, int); int -main (int ac, char **av) +main (int argc, char **argv) { int sig = SIGTERM; + int force = 0; + int gotsig = 0; - if (ac == 1) + if (argc == 1) usage (); - if (*(++av)[0] == '-') - if (strcmp(*av + 1, "0") != 0) - sig = getsig (*av++ + 1); + while (*(++argv)[0] == '-') + if (strcmp (*argv + 1, "f") == 0) + force = 1; + else if (gotsig) + break; + else if (strcmp(*argv + 1, "0") != 0) + { + sig = getsig (*argv++ + 1); + gotsig = 1; + } else { - av++; + argv++; sig = 0; goto sig0; } if (sig <= 0 || sig > NSIG) { - fprintf (stderr, "kill: unknown signal: %s\n", av[-1]); + fprintf (stderr, "kill: unknown signal: %s\n", argv[-1]); exit (1); } sig0: - while (*av != NULL) + while (*argv != NULL) { char *p; - int pid = strtol (*av, &p, 10); + int pid = strtol (*argv, &p, 10); if (*p != '\0') - fprintf (stderr, "kill: illegal pid: %s\n", *av); + fprintf (stderr, "kill: illegal pid: %s\n", *argv); else { +#if 0 printf ("Sending %s(%d) signal to pid %d\n", strsignal (sig), sig, pid); +#endif if (kill (pid, sig)) - perror ("kill"); + { + if (errno == ESRCH && force && sig != 0) + forcekill (pid, sig); + else + { + char buf[1000]; + sprintf (buf, "kill %d", pid); + perror (buf); + } + } } - av++; + argv++; } return 0; } @@ -83,3 +105,13 @@ getsig (char *in_sig) } return (strtosigno (sig) ?: atoi (in_sig)); } + +static void __stdcall +forcekill (int pid, int sig) +{ + HANDLE h = OpenProcess (PROCESS_TERMINATE, FALSE, (DWORD) pid); + if (!h) + return; + TerminateProcess (h, sig << 8); + CloseHandle (h); +} |