2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1999-2009 Oracle. All rights reserved.
10 * Simulate Unix kill on Windows/NT and Windows/9X.
11 * This good enough to support the Berkeley DB test suite,
12 * but may be missing some favorite features.
14 * Would have used MKS kill, but it didn't seem to work well
15 * on Win/9X. Cygnus kill works within the Gnu/Cygnus environment
16 * (where processes are given small pids, with presumably a translation
17 * table between small pids and actual process handles), but our test
18 * environment, via Tcl, does not use the Cygnus environment.
20 * Compile this and install it as c:/tools/kill.exe (or as indicated
21 * by build_windows/include.tcl ).
30 * Like atol, with specified base. Would use stdlib, but
31 * strtol("0xFFFF1234", NULL, 16) returns 0x7FFFFFFF and
32 * strtol("4294712487", NULL, 16) returns 0x7FFFFFFF w/ VC++
35 myatol(char *s, int base)
42 if (base != 10 && base != 16)
44 while ((ch = *s++) != '\0') {
48 else if (ch >= '0' && ch <= '9') {
49 result = result * base + (ch - '0');
51 else if (ch == 'x' || ch == 'X') {
52 /* Allow leading 0x..., and switch to base 16 */
55 else if (base == 16 && ch >= 'a' && ch <= 'f') {
56 result = result * base + (ch - 'a' + 10);
58 else if (base == 16 && ch >= 'A' && ch <= 'F') {
59 result = result * base + (ch - 'A' + 10);
74 fprintf(stderr, "Usage: kill [ -sig ] pid\n");
75 fprintf(stderr, " for win32, sig must be or 0, 15 (TERM)\n");
80 main(int argc, char **argv)
88 if (argv[1][0] != '-')
91 if (strcmp(argv[1], "-TERM") == 0)
94 /* currently sig is more or less ignored,
95 * we only care if it is zero or not
97 sig = atoi(&argv[1][1]);
107 pid = myatol(argv[1], 10);
108 /*printf("pid = %ld (0x%lx) (command line %s)\n", pid, pid, argv[1]);*/
109 if (pid == LONG_MAX || pid == LONG_MIN)
113 accessflag = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ;
115 accessflag = STANDARD_RIGHTS_REQUIRED | PROCESS_TERMINATE;
116 hProcess = OpenProcess(accessflag, FALSE, pid);
117 if (hProcess == NULL) {
118 fprintf(stderr, "dbkill: %s: no such process\n", argv[1]);
123 if (!TerminateProcess(hProcess, 99)) {
124 DWORD err = GetLastError();
126 "dbkill: cannot kill process: error %d (0x%lx)\n", err, err);