[vox-tech] Identifying the directory that contains the currently running executable?

Bill Kendrick nbs at sonic.net
Fri Aug 27 10:30:56 PDT 2004


On Fri, Aug 27, 2004 at 10:28:27AM -0700, Ken Bloom wrote:
> Is there a way to identify the directory that contains the currently
> running executable, so that I can programmatically refer to it?
> i.e. if I am running /usr/bin/myprog, but pwd is /home/bloom, how can
> I programmatically get either the pathname '/usr/bin' or
> '/usr/bin/myprog'. (This question asks about a C program).

Not sure programmatically, but /proc/$PID/exe is a symlink to the 
program.

For example, I did "ps aux | grep mysql", found the PID of my
MySQL client was "4753", and then saw:

  lrwx------    1 username username      0 Aug 27 10:29 exe -> /usr/bin/mysql

inside "/proc/4753/"


Does that help at all? :)

-bill!


More information about the vox-tech mailing list