There is the name of the currently running process and its Pid. How can I get the full (absolute) path to the executable file of this process in java or si?

  • 3
    What operating system? Want to write how this is done in OS / 2? :) - Harry
  • For example: sudo readlink /proc/$PID/exe . On C - man 2 readlink - PinkTux
  • @Harry and write! =) - Vartlok
  • @Vartlok Something like this I once did - I needed the entire list: vpaste.net/ocF4V Now I don’t remember exactly which calls to get a ModuleHandle for Pid, ​​but if you really need it, I can search ... - Harry
  • @Harry I mean that you write the answer (if not laziness), I think it may be useful to someone. - Vartlok

2 answers 2

For Windows: OpenProcess () + QueryFullProcessImageName ()

    For Linux. Run the command pipeline

     ps --pid <PID процесса> -f | tail -n1 | awk '{print($8)}' 

    when calling popen:

     FILE *ff = popen("Конвейер команд", "r"); 

    And then read the line from the ff file.