How Does a Program Know Where it is Running?

Dave Mielke dave at mielke.cc
Sun May 2 22:20:03 UTC 2004


[quoted lines by John J. Boyer on 2004/05/02 at 16:24 -0500]

>How does a program find out in which directory it resides?  I've tried
>argv[0], but if the program is started via a link that just contains she
>name of the link.

If you don't mind the program being tied to Linux (as opposed to any other
Unix-flavoured operating system), then do a readlink() on /proc/self/exe.

-- 
Dave Mielke           | 2213 Fox Crescent | I believe that the Bible is the
Phone: 1-613-726-0014 | Ottawa, Ontario   | Word of God. Please contact me
EMail: dave at mielke.cc | Canada  K2A 1H7   | if you're concerned about Hell.
http://familyradio.com/                   | http://mielke.cc/bible/





More information about the Blinux-list mailing list