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