0

I am trying to write a routine that returns from a given PID path to its binary file or executable, depending on platform. I know it can be done on windows using windows.h, but that is platform dependent solution.

I was trying to find a solution using Qt, but I got nowhere near my goal, because there is no way to construct QProcess or any other class using provided PID.

But boost(v1.66) has a class boost::process::child, which can be constructed using provided PID, and can even return native handle (boost::process::child::native_handle_t). But from there I do not know.

It does not have any methods (which does not surprise, because it seems to be alias for void*), but I could not find any method extracting any information from this "class" either.

So is there a way to extract the information about location of the binary from a given PID using boost or there isn't ??

Draft of the function:

boost::filesystem::path GetExecutable (boost::process::pid_t pid) {
   boost::filesystem::path path_to_executable;

   bp::child process (pid);
   boost::process::child::native_handle_t handle = process.native_handle();
      .
      .
      .
   return path_to_executable;
}
TStancek
  • 310
  • 1
  • 12

1 Answers1

0

boost::process::child isn't really meant for this. It will merely treat the pid passed as a child process, so you can do operations such as joining, seeing if it is still running, terminating, checking for return values, etc. It will, of course, need the correct access permissions if it wants to do those operations.

You could get a native handle (using child::native_handle()), but that is merely the pid you already provided when constructing it, so you would just be back to square one.

The simple answer, then, is "No". You cannot do it using boost::process::child.

Not a real meerkat
  • 5,604
  • 1
  • 24
  • 55
  • On windows at least, native_handle() returns void* (as I mentioned in my question). But I was hoping for some way to extract the name, using some function or pretty much anything boost-native... So, there really is not anything? – TStancek Jun 11 '19 at 08:45