|
Boost : |
Subject: Re: [boost] [boost.process] Review
From: Joseph Van Riper (fleeb.fantastique_at_[hidden])
Date: 2016-10-27 12:20:57
Within Windows, you can also get the parent process ID using
CreateToolhelp32Snapshot and walking the process list via
Process32First/Process32Next (as well as the threads with
Thread32First/Thread32Next, if you want that). The PROCESSENTRY32
structure has a th32ParentProcessID with what you want.
(Heh, also not straightforward).
I do not know which method works better, but I've done the above from XP
through Win10, 64-32bit.
- Trey
On Mon, Oct 24, 2016 at 6:31 PM Klemens Morgenstern <
klemens.morgenstern_at_[hidden]> wrote:
> Am 24.10.2016 um 23:58 schrieb Remi Chateauneu:
> > "Get the parent process id ?"
> >
> > I found and successfully tested this on Windows 7:
> >
> http://stackoverflow.com/questions/185254/how-can-a-win32-process-get-the-pid-of-its-parent
> >
> > ULONG_PTR GetParentProcessId() // By Napalm @ NetCore2K{
> > ULONG_PTR pbi[6];
> > ULONG ulSize = 0;
> > LONG (WINAPI *NtQueryInformationProcess)(HANDLE ProcessHandle, ULONG
> > ProcessInformationClass,
> > PVOID ProcessInformation, ULONG ProcessInformationLength, PULONG
> > ReturnLength);
> > *(FARPROC *)&NtQueryInformationProcess =
> > GetProcAddress(LoadLibraryA("NTDLL.DLL"),
> "NtQueryInformationProcess");
> > if(NtQueryInformationProcess){
> > if(NtQueryInformationProcess(GetCurrentProcess(), 0,
> > &pbi, sizeof(pbi), &ulSize) >= 0 && ulSize == sizeof(pbi))
> > return pbi[5];
> > }
> > return (ULONG_PTR)-1;}
> >
> >
> Neat. I hope you don't have a problem, if I do in fact consider that not
> straight-forward. Though to be fair, I had code like that in my library
> too, before I realized that the particular problem was easier to solve.
> Not sure however, why the function returns a pointer.
> It's also a bit ugly, since the Nt* functions have errorcodes different
> from the regular API functions - and you can run into a number of access
> right errors here.
>
> Well the review starts on thursday, so considering, that I might still
> get an urgent bugfix and have a dayjob, I'd think that's to little time
> to get a solid version into the library. We'll do it afterwards, but
> this shouldn't be a problem. So you'd have two functions:
>
> child::get_parent_id();
> this_process::get_parent_id();
>
> If you want to help me out here, the pattern is this: Implementation in
> boost::process::detail::windows/posix, two times, on that throws, one
> that uses std::error_code, and then using them in the higher layer
> though the namespace alias api, i.e. boost::process::api. Also the
> implementation must use boost.winapi, so windows.h does not get included.
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk