Get process name w/o using argv[0] in C function?
Michael P. Lindner
mpl at pegasus.ATT.COM
Wed Aug 1 05:34:42 AEST 1990
In article <9220003 at hpldsla.sid.hp.com> manoj at hpldsla.sid.hp.com (Manoj Joshi) writes:
>Is there a way to get the name of a process anywhere inside the source?
deleted
>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!
deleted
>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.
deleted
>Manoj.
No. There is no way to do this. I do not understand why you would rather
write code to scan through the proc table (which, incidentally, will require
a setuid or setgid for your program and introduce all sorts of security
risks) than use a global. If you know your architecture, you can do a stack
trace on your process from inside to get to argv, but that is non-portable
and ugly, too (although I have a routine which does it - I like ugly things,
sometimes :^) My recommendation: BREAK DOWN AND USE A GLOBAL.
Mike Lindner
attmail!mplindner
More information about the Comp.unix.questions
mailing list