GetModuleFileName() in Linux

I need a way to get the complete path/filename of a executable into them (Running on Linux). Similar to Windows GetModuleFileName().
NOTE: The complete path/filename where the executable file are.
manloreAsked:
Who is Participating?
 
Stefan_PConnect With a Mentor Commented:
There is no official, nice & easy way to do this. You have to do one of the following:

A) Look in the /proc directory. There is a subdirectory for each process (/proc/<pid>) that tells you which file is executed (there is a symblic link, use lstat() to find out what file it points to). You can determine the PID of your process using getpid(). Note that this works only under Linux, other Unices don't support the proc filesystem.

B) The hard way. Examine argv[0]. If it does not contain path information (only a file name), you have to scan all directories that are listed in your PATH environment variable (getenv("PATH")). This requires considerable programming effort.
0
 
manloreAuthor Commented:
The complete path/filename where the executable file are.
0
 
manloreAuthor Commented:
Edited text of question.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
manloreAuthor Commented:
Edited text of question.
0
 
manloreAuthor Commented:
Edited text of question.
0
 
manloreAuthor Commented:
Thaks for your answer.
The A option works fine.
¿Do you now if the A option works on Solaris?
0
 
Stefan_PCommented:
Solaris actually has a /proc directory structure, but its contents are different. As far as I know, there is no information about the executable's path. <Sigh>
0
All Courses

From novice to tech pro — start learning today.