Unfortunately, there is no standardized way on different unix systems
to access the path of the executable running (it's not even fully
clear what it means in the presence of symlinks, etc). Actually it seems
to be impossible to do this (without argv[0]) on certain BSD systems.
Also note:
- argv[0] won't be a full pathname if the program was found via $PATH search
- it is possible for users to pass arbitrary argv[0] to the exec() family of system calls
- some programs use special argv[0] values (this probably doesn't practically matter), notably shells look for a leading "-" (which is normally provided by "login" or "sshd" etc.) to indicate a login shell that should source ~/.profile etc.
- there are various other special cases, such as a number of Unixlikes implementing setuid shell scripts securely by passing a /dev/fd/* reference as argv[0] to avoid symlink attacks. Again, you *probably* don't need to care about this one, but there may be others on various systems.
In short, argv[0] should not be relied on as the executable name.
(The usual way this is managed is that the real executable is something like foo.real and foo is a shell script which passes in the path to foo.real as a parameter. During installation/configuration the shell script is modified as necessary to provide the correct path.)