From 903abcceb656701cd57a94404f1e13626618b1c9 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Wed, 15 Sep 2010 09:44:01 +1000 Subject: win32: reimplement procps_scan() On Linux, procps_scan() relies on /proc, which is obviously unavailable on Windows. This implementation currently supports procps_status_t.{pid,comm} only. --- win32/process.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'win32') diff --git a/win32/process.c b/win32/process.c index 13bf81797..1b9b61878 100644 --- a/win32/process.c +++ b/win32/process.c @@ -1,4 +1,5 @@ #include "libbb.h" +#include int waitpid(pid_t pid, int *status, unsigned options) { @@ -284,3 +285,35 @@ mingw_execv(const char *cmd, const char *const *argv) { return mingw_execve(cmd, argv, (const char *const *)environ); } + +/* POSIX version in libbb/procps.c */ +procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) +{ + PROCESSENTRY32 pe; + + pe.dwSize = sizeof(pe); + if (!sp) { + sp = xzalloc(sizeof(struct procps_status_t)); + sp->snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (sp->snapshot == INVALID_HANDLE_VALUE) { + free(sp); + return NULL; + } + if (!Process32First(sp->snapshot, &pe)) { + CloseHandle(sp->snapshot); + free(sp); + return NULL; + } + } + else { + if (!Process32Next(sp->snapshot, &pe)) { + CloseHandle(sp->snapshot); + free(sp); + return NULL; + } + } + + sp->pid = pe.th32ProcessID; + strncpy(sp->comm, pe.szExeFile, COMM_LEN); + return sp; +} -- cgit v1.2.3-55-g6feb