--- posixmodule-orig.c Wed Jul 01 10:35:00 2009 +++ posixmodule.c Wed Jul 01 10:41:30 2009 @@ -122,6 +122,7 @@ #else #ifdef _MSC_VER /* Microsoft compiler */ #define HAVE_GETCWD 1 +#define HAVE_GETPPID 1 #define HAVE_SPAWNV 1 #define HAVE_EXECV 1 #define HAVE_PIPE 1 @@ -3889,15 +3890,52 @@ #endif /* HAVE_SETPGRP */ +#ifdef MS_WINDOWS +#include +pid_t win32_getppid() +{ + HANDLE snapshot; + pid_t parentpid, mypid; + parentpid = (pid_t)-1; + + mypid = getpid(); + snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (INVALID_HANDLE_VALUE != snapshot) { + BOOL have_record; + PROCESSENTRY32 pe; + + pe.dwSize = sizeof(pe); + have_record = Process32First(snapshot, &pe); + while (have_record) { + if (mypid == (pid_t)pe.th32ProcessID) { + /* We could cache this value in a static variable. */ + parentpid = pe.th32ParentProcessID; + break; + } + + have_record = Process32Next(snapshot, &pe); + } + + CloseHandle(snapshot); + } + + return parentpid; +} +#endif /*MS_WINDOWS*/ + #ifdef HAVE_GETPPID PyDoc_STRVAR(posix_getppid__doc__, "getppid() -> ppid\n\n\ -Return the parent's process id."); +Return the parent's process id, or -1 upon error."); static PyObject * posix_getppid(PyObject *self, PyObject *noargs) { +#ifdef MS_WINDOWS + return PyLong_FromPid(win32_getppid()); +#else return PyLong_FromPid(getppid()); +#endif } #endif --- C:/Users/janglin/AppData/Local/Temp/os.rst-revBASE.svn000.tmp.rst Wed Jul 1 10:27:45 2009 +++ L:/python/svn/python/Doc/library/os.rst Wed Jul 1 10:26:56 2009 @@ -171,7 +171,7 @@ .. index:: single: process; id of parent - Return the parent's process id. Availability: Unix. + Return the parent's process id, or -1 if an error occurs (Windows only). Availability: Unix, Windows. .. function:: getuid()