Get process name w/o using argv[0] in C function?

Manoj Joshi manoj at hpldsla.sid.hp.com
Tue Jul 31 10:48:47 AEST 1990


Is there a way to get the name of a process anywhere inside the source?
By name, I mean argv[0]. As an alternative, I can pass argv[0] as an
extra parameter from main() to every function in the program, but I 
think it is inefficient. Also, I do not think I want to use a global
and initialize it to argv[0] in body of main(), because I do not use
globals!

I know that getpid() and getppid() get me the process id and parent's
process id. From this I can scan thru the proc table in proc.h, and
get the process name as a string. But this may be non-portable C.
Note that __FILE__ does not solve my problem, because it does not return
the name of the final executable, but only the current source file.

Anyone find  out how to do this?

Manoj.



More information about the Comp.unix.questions mailing list