Sunday, December 4, 2011

Programmers' Advent Calendar: #3 How to find a program's executable (C/C++)

Say you are writing a C/C++ program and from within that program you need to find the path of the exe file. Under *nix systems. Get the pid, "int pid = getpid();" then simply the file "/proc/pid/exe" is a link to the executable. From there you can do whatever you want. You can also find a bunch of other information about your process in the "/proc/pid/" directory. Come back for more tomorrow :).

No comments: