From d10f0e106e5bbc20d84722e9d45a6e8623d96e2d Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 10 Aug 2011 13:13:09 +0000 Subject: * fhandler_process.cc (format_process_status): Always print process name even for zombies. (get_mem_values): Fix loop fetching working set list to avoid out of memory conditions. Return all mem values set to 0 for zombies. * ntdll.h (STATUS_PROCESS_IS_TERMINATING): Define. --- winsup/cygwin/ChangeLog | 8 ++++++ winsup/cygwin/fhandler_process.cc | 53 ++++++++++++++++++--------------------- winsup/cygwin/ntdll.h | 1 + 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index cdb1560..7696cbe 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +2011-08-10 Corinna Vinschen + + * fhandler_process.cc (format_process_status): Always print process name + even for zombies. + (get_mem_values): Fix loop fetching working set list to avoid out of + memory conditions. Return all mem values set to 0 for zombies. + * ntdll.h (STATUS_PROCESS_IS_TERMINATING): Define. + 2011-08-09 Corinna Vinschen * heap.cc (eval_initial_heap_size): New function fetching the heap diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc index a4df4d6..09ca2c7 100644 --- a/winsup/cygwin/fhandler_process.cc +++ b/winsup/cygwin/fhandler_process.cc @@ -1135,21 +1135,16 @@ format_process_status (void *data, char *&destbuf) const char *state_str = "unknown"; unsigned long vmsize = 0UL, vmrss = 0UL, vmdata = 0UL, vmlib = 0UL, vmtext = 0UL, vmshare = 0UL; - if (p->process_state & PID_EXITED) - strcpy (cmd, ""); - else + PWCHAR last_slash = wcsrchr (p->progname, L'\\'); + wcscpy (wcmd, last_slash ? last_slash + 1 : p->progname); + sys_wcstombs (cmd, NAME_MAX + 1, wcmd); + int len = strlen (cmd); + if (len > 4) { - PWCHAR last_slash = wcsrchr (p->progname, L'\\'); - wcscpy (wcmd, last_slash ? last_slash + 1 : p->progname); - sys_wcstombs (cmd, NAME_MAX + 1, wcmd); - int len = strlen (cmd); - if (len > 4) - { - char *s = cmd + len - 4; - if (ascii_strcasematch (s, ".exe")) - *s = 0; - } - } + char *s = cmd + len - 4; + if (ascii_strcasematch (s, ".exe")) + *s = 0; + } /* * Note: under Windows, a _process_ is always running - it's only _threads_ * that get suspended. Therefore the default state is R (runnable). @@ -1370,27 +1365,29 @@ get_mem_values (DWORD dwProcessId, unsigned long *vmsize, unsigned long *vmrss, debug_printf ("OpenProcess, %E"); return false; } - do + while (true) { ret = NtQueryVirtualMemory (hProcess, 0, MemoryWorkingSetList, (PVOID) p, n, (length = ULONG_MAX, &length)); - if (ret == STATUS_INFO_LENGTH_MISMATCH - || (!NT_SUCCESS (ret) && length > n)) - { - ret = STATUS_INFO_LENGTH_MISMATCH; - n <<= 1; - PMEMORY_WORKING_SET_LIST new_p = (PMEMORY_WORKING_SET_LIST) - realloc (p, n); - if (!new_p) - goto out; - p = new_p; - } + if (ret != STATUS_INFO_LENGTH_MISMATCH) + break; + n <<= 1; + PMEMORY_WORKING_SET_LIST new_p = (PMEMORY_WORKING_SET_LIST) + realloc (p, n); + if (!new_p) + goto out; + p = new_p; } - while (!NT_SUCCESS (ret)); if (!NT_SUCCESS (ret)) { debug_printf ("NtQueryVirtualMemory: ret %p", ret); - __seterrno_from_nt_status (ret); + if (ret == STATUS_PROCESS_IS_TERMINATING) + { + *vmsize = *vmrss = *vmtext = *vmdata = *vmlib = *vmshare = 0; + res = true; + } + else + __seterrno_from_nt_status (ret); goto out; } mwsl = (MEMORY_WORKING_SET_LIST *) p; diff --git a/winsup/cygwin/ntdll.h b/winsup/cygwin/ntdll.h index b317e66..c5b3597 100644 --- a/winsup/cygwin/ntdll.h +++ b/winsup/cygwin/ntdll.h @@ -52,6 +52,7 @@ #define STATUS_INVALID_NETWORK_RESPONSE ((NTSTATUS) 0xc00000c3) #define STATUS_BAD_NETWORK_NAME ((NTSTATUS) 0xc00000cc) #define STATUS_DIRECTORY_NOT_EMPTY ((NTSTATUS) 0xc0000101) +#define STATUS_PROCESS_IS_TERMINATING ((NTSTATUS) 0xc000010a) #define STATUS_CANNOT_DELETE ((NTSTATUS) 0xc0000121) #define STATUS_INVALID_LEVEL ((NTSTATUS) 0xc0000148) #define STATUS_DLL_NOT_FOUND ((NTSTATUS) 0xc0000135) -- cgit v1.1