Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!gem.mps.ohio-state.edu!ginosko!uunet!pilchuck!pacer!davidb From: davidb@Pacer.UUCP (David Barts) Newsgroups: comp.unix.wizards Subject: Re: Reading the symbol table of the currently running executable Summary: Getting the path of the current executable Message-ID: <244@zircon.UUCP> Date: 7 Sep 89 15:49:51 GMT References: <9104@june.cs.washington.edu> <6131@lynx.UUCP> Organization: Pacer Corp., Bothell, WA Lines: 29 In article <6131@lynx.UUCP>, mitch@lynx.uucp (Mitch Bunnell) writes: > In article <9104@june.cs.washington.edu> bcn@cs.washington.edu (Clifford Neuman) writes: > > > > 1) Directly reading the symbol table from within the running program > > > > 2) Obtaining the full path name of the presently running executable. > > > > 3) Obtaining a file descriptor for the currently running executable > > > 1 - Not possible. The symbol table is NOT loaded with the program. > > 2 - Not possible. True, it's not possible to do this in a fail-safe manner guarenteed to work all the time. But you can usually figure it out by reading argv[0] and PATH and applying the same rules the shell does in determining the location of an executable. Should work if the program was run from the shell by its true name, and you do this before modifying PATH or calling chdir(2) or chroot(2). If the program was invoked via an alias, you may or may not have trouble depending on how the shell you use handles aliases (they are not all the same!). All bets are off if the program has been exec'ed with argv[0] != program_name (often the case if the executable is a shell or was exec'ed by login(1)). -- David Barts Pacer Corporation davidb@pacer.uucp ...!fluke!pacer!davidb