summaryrefslogtreecommitdiffstats
path: root/win32
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-24 02:14:00 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-24 02:14:00 +0000
commit040bf28e0773a748ac14427a51738bb6f07dbd95 (patch)
treea0cefc7c5255c3c1e47614856633c75f0e07d2c7 /win32
parent7435cf8c5a9799e43c26d9b5d3fa6fb4c99925eb (diff)
downloadruby-040bf28e0773a748ac14427a51738bb6f07dbd95.tar.gz
ruby-040bf28e0773a748ac14427a51738bb6f07dbd95.tar.xz
ruby-040bf28e0773a748ac14427a51738bb6f07dbd95.zip
* include/ruby/win32.h, win32/win32.c (rb_w32_getppid): now support
getppid() on win32 (but only Win2k or later). * process.c (get_ppid): remove win32 special logic. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@17553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c
index e79bbf2ba..dec12eb8d 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3829,6 +3829,40 @@ rb_w32_getpid(void)
return pid;
}
+
+rb_pid_t
+rb_w32_getppid(void)
+{
+ static long (WINAPI *pNtQueryInformationProcess)(HANDLE, int, void *, ULONG, ULONG *) = NULL;
+ rb_pid_t ppid = 0;
+
+ if (!IsWin95() && rb_w32_osver() >= 5) {
+ if (!pNtQueryInformationProcess) {
+ HANDLE hNtDll = GetModuleHandle("ntdll.dll");
+ if (hNtDll) {
+ pNtQueryInformationProcess = (long (WINAPI *)(HANDLE, int, void *, ULONG, ULONG *))GetProcAddress(hNtDll, "NtQueryInformationProcess");
+ if (pNtQueryInformationProcess) {
+ struct {
+ long ExitStatus;
+ void* PebBaseAddress;
+ ULONG AffinityMask;
+ ULONG BasePriority;
+ ULONG UniqueProcessId;
+ ULONG ParentProcessId;
+ } pbi;
+ ULONG len;
+ long ret = pNtQueryInformationProcess(GetCurrentProcess(), 0, &pbi, sizeof(pbi), &len);
+ if (!ret) {
+ ppid = pbi.ParentProcessId;
+ }
+ }
+ }
+ }
+ }
+
+ return ppid;
+}
+
int
rb_w32_fclose(FILE *fp)
{