Reading the symbol table of the currently running executable

David Barts davidb at Pacer.UUCP
Fri Sep 8 01:49:51 AEST 1989


In article <6131 at lynx.UUCP>, mitch at lynx.uucp (Mitch Bunnell) writes:
> In article <9104 at june.cs.washington.edu> bcn at 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 at pacer.uucp		...!fluke!pacer!davidb



More information about the Comp.unix.wizards mailing list