On Windows the Perl
getppid is not implemented. I have used the following C code in some of my XS modules:
#include <windows.h>
#include <tlhelp32.h>
static int getppid(void) {
HANDLE hToolSnapshot;
PROCESSENTRY32 Pe32 = {0};
BOOL bResult;
DWORD PID;
DWORD PPID = 0;
PID = GetCurrentProcessId ();
hToolSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hToolSnapshot == INVALID_HANDLE_VALUE) {
return 0;
}
Pe32.dwSize = sizeof(PROCESSENTRY32);
bResult = Process32First(hToolSnapshot, &Pe32);
if (!bResult)
return 0;
while ( Process32Next(hToolSnapshot, &Pe32) ) {
if (Pe32.th32ProcessID == PID) {
PPID = Pe32.th32ParentProcessID;
break;
}
}
/* Expected */
if (GetLastError() == ERROR_NO_MORE_FILES) {
SetLastError(ERROR_SUCCESS);
}
return PPID;
}
Ah, I see you have upgraded to Linux, maybe it might be useful to some poor Windows coder.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.