How does a program get its path name?
der Mouse
mouse at mcgill-vision.UUCP
Sun Mar 13 13:34:41 AEST 1988
In article <2933 at sdsu.UUCP>, turtle at sdsu.UUCP (Andrew Scherpbier) writes:
> In article <11923 at brl-adm.ARPA> Leisner.Henr at xerox.com (marty) writes:
>> How does an exec program get the pathname it was execed from if it
>> wants to find out this information?
In general, it can't.
> When a program executes, the full path to the executable file is kept
> in the zero-th argument. If you have a declaration of main which
> looks like this:
> main(argc,argv) int argc; char *argv[];
> then argv[0] is a pointer to the full path.
Not at all. argv[0] is merely whatever was passed to the exec-family
routine that executed the program. The shell conventionally passes
whatever name the program was called by in this field, but this (a) is
not always a full pathname and (b) is not a universal convention in the
first place. If a program wants, it can run your program and make
argv[0] be "/bin/sh", or "Jan 23 1988, 11:44:82.35 GMT", or whatever it
pleases.
der Mouse
uucp: mouse at mcgill-vision.uucp
arpa: mouse at larry.mcrcim.mcgill.edu
More information about the Comp.unix.questions
mailing list