diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc index 3a9130efd..ae30695a1 100644 --- a/winsup/cygwin/external.cc +++ b/winsup/cygwin/external.cc @@ -63,19 +63,23 @@ fillout_pinfo (pid_t pid, int winpid) _pinfo *p = pids[i]; i++; + /* Native Windows process not started from Cygwin have no procinfo + attached. They don't have a real Cygwin PID either. We fake a + Cygwin PID beyond MAX_PID. */ if (!p) { - if (!nextpid && thispid != (DWORD) pid) + if (!nextpid && thispid + MAX_PID != (DWORD) pid) continue; - ep.pid = cygwin_pid (thispid); + ep.pid = thispid + MAX_PID; ep.dwProcessId = thispid; ep.process_state = PID_IN_USE; ep.ctty = -1; break; } - else if (nextpid || p->pid == pid || (winpid && thispid == (DWORD) pid)) + else if (nextpid || p->pid == pid) { - ep.ctty = (p->ctty < 0 || iscons_dev (p->ctty)) ? p->ctty : device::minor (p->ctty); + ep.ctty = (p->ctty < 0 || iscons_dev (p->ctty)) + ? p->ctty : device::minor (p->ctty); ep.pid = p->pid; ep.ppid = p->ppid; ep.dwProcessId = p->dwProcessId; diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 98168c76a..c9025774f 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -241,7 +241,7 @@ create_cygwin_pid () do { pid = ((uint32_t) InterlockedIncrement (&cygwin_shared->pid_src)) - % 65536; + % MAX_PID; } while (pid < 2); __small_swprintf (sym_name, L"cygpid.%u", pid); diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h index 81e10d3d5..a1e5afe23 100644 --- a/winsup/cygwin/pinfo.h +++ b/winsup/cygwin/pinfo.h @@ -211,6 +211,8 @@ private: DWORD status_exit (DWORD); }; +#define MAX_PID 65536 + #define ISSTATE(p, f) (!!((p)->process_state & f)) #define NOTSTATE(p, f) (!((p)->process_state & f))