diff options
| author | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-09-10 20:11:45 +0100 |
|---|---|---|
| committer | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-09-10 20:11:45 +0100 |
| commit | 8703b01c40289a5eba6ea8d7832a8a1a6d60ff4a (patch) | |
| tree | 48fbb86001c109e261593569ef9dc61053d6798c /psutil/arch | |
| parent | 3070b961719320f606fb828b0aed91aab903a1a8 (diff) | |
| download | psutil-8703b01c40289a5eba6ea8d7832a8a1a6d60ff4a.tar.gz | |
Fix issue #416 (Windows) / http://stackoverflow.com/questions/6587036/alternative-to-psutil-processpid-name: make Process.name an order of magnitude faster by avoiding to iterate over all processes returned by CreateToolhelp32Snapshot(). Relying on CreateToolhelp32Snapshot() is just stupid because we can use the base name of process executable (already implemented and obtained via GetProcessImageFileName()).
Diffstat (limited to 'psutil/arch')
| -rw-r--r-- | psutil/arch/mswindows/process_info.c | 28 | ||||
| -rw-r--r-- | psutil/arch/mswindows/process_info.h | 1 |
2 files changed, 0 insertions, 29 deletions
diff --git a/psutil/arch/mswindows/process_info.c b/psutil/arch/mswindows/process_info.c index f1f434bc..0f464c3a 100644 --- a/psutil/arch/mswindows/process_info.c +++ b/psutil/arch/mswindows/process_info.c @@ -216,34 +216,6 @@ handlep_is_running(HANDLE hProcess) } -// Return None to represent NoSuchProcess, else return NULL for -// other exception or the name as a Python string -PyObject* -psutil_get_name(long pid) -{ - HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); - PROCESSENTRY32 pe = { 0 }; - pe.dwSize = sizeof(PROCESSENTRY32); - - if( Process32First(h, &pe)) { - do { - if (pe.th32ProcessID == pid) { - CloseHandle(h); - return Py_BuildValue("s", pe.szExeFile); - } - } while(Process32Next(h, &pe)); - - // the process was never found, set NoSuchProcess exception - NoSuchProcess(); - CloseHandle(h); - return NULL; - } - - CloseHandle(h); - return PyErr_SetFromWindowsErr(0); -} - - /* * returns a Python list representing the arguments for the process * with given pid or NULL on error. diff --git a/psutil/arch/mswindows/process_info.h b/psutil/arch/mswindows/process_info.h index 060868c0..aa54c9d2 100644 --- a/psutil/arch/mswindows/process_info.h +++ b/psutil/arch/mswindows/process_info.h @@ -18,5 +18,4 @@ int psutil_pid_in_proclist(DWORD pid); int psutil_pid_is_running(DWORD pid); int psutil_handlep_is_running(HANDLE hProcess); PyObject* psutil_get_arg_list(long pid); -PyObject* psutil_get_name(long pid); DWORD* psutil_get_pids(DWORD *numberOfReturnedPIDs); |
