diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-15 16:33:33 +1000 |
---|---|---|
committer | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2010-09-15 16:33:33 +1000 |
commit | 924d22029b978432c4a65a905a981b4661102edf (patch) | |
tree | 469957575269fabe3e8b7ddb412123da22185a4c /win32 | |
parent | c5ef3a03d7d111634a1d2e4f72dcb1102049b592 (diff) | |
parent | 4fd7461aeaac63edb004696e722bf36e7f6f402c (diff) | |
download | busybox-w32-924d22029b978432c4a65a905a981b4661102edf.tar.gz busybox-w32-924d22029b978432c4a65a905a981b4661102edf.tar.bz2 busybox-w32-924d22029b978432c4a65a905a981b4661102edf.zip |
Merge branch 'procps'
Diffstat (limited to 'win32')
-rw-r--r-- | win32/process.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/win32/process.c b/win32/process.c index 13bf81797..cdd71182b 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #include "libbb.h" | 1 | #include "libbb.h" |
2 | #include <tlhelp32.h> | ||
2 | 3 | ||
3 | int waitpid(pid_t pid, int *status, unsigned options) | 4 | int waitpid(pid_t pid, int *status, unsigned options) |
4 | { | 5 | { |
@@ -284,3 +285,52 @@ mingw_execv(const char *cmd, const char *const *argv) | |||
284 | { | 285 | { |
285 | return mingw_execve(cmd, argv, (const char *const *)environ); | 286 | return mingw_execve(cmd, argv, (const char *const *)environ); |
286 | } | 287 | } |
288 | |||
289 | /* POSIX version in libbb/procps.c */ | ||
290 | procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) | ||
291 | { | ||
292 | PROCESSENTRY32 pe; | ||
293 | |||
294 | pe.dwSize = sizeof(pe); | ||
295 | if (!sp) { | ||
296 | sp = xzalloc(sizeof(struct procps_status_t)); | ||
297 | sp->snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); | ||
298 | if (sp->snapshot == INVALID_HANDLE_VALUE) { | ||
299 | free(sp); | ||
300 | return NULL; | ||
301 | } | ||
302 | if (!Process32First(sp->snapshot, &pe)) { | ||
303 | CloseHandle(sp->snapshot); | ||
304 | free(sp); | ||
305 | return NULL; | ||
306 | } | ||
307 | } | ||
308 | else { | ||
309 | if (!Process32Next(sp->snapshot, &pe)) { | ||
310 | CloseHandle(sp->snapshot); | ||
311 | free(sp); | ||
312 | return NULL; | ||
313 | } | ||
314 | } | ||
315 | |||
316 | sp->pid = pe.th32ProcessID; | ||
317 | strncpy(sp->comm, pe.szExeFile, COMM_LEN); | ||
318 | return sp; | ||
319 | } | ||
320 | |||
321 | int kill(pid_t pid, int sig) | ||
322 | { | ||
323 | HANDLE h; | ||
324 | |||
325 | if (sig != SIGTERM) { | ||
326 | bb_error_msg("kill only supports SIGTERM"); | ||
327 | errno = ENOSYS; | ||
328 | return -1; | ||
329 | } | ||
330 | h = OpenProcess(PROCESS_TERMINATE, FALSE, pid); | ||
331 | if (h == NULL) | ||
332 | return -1; | ||
333 | if (TerminateProcess(h, 0) == 0) | ||
334 | return -1; | ||
335 | return 0; | ||
336 | } | ||