Boost logo

Boost :

Subject: Re: [boost] [boost.process] Review
From: Klemens Morgenstern (klemens.morgenstern_at_[hidden])
Date: 2016-10-24 18:31:13


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.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk