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

Peter da Silva peter at ficc.ferranti.com
Thu Aug 2 04:46:14 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?
> 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!

Why not? This is guaranteed global per-process static data. There is no
reason not to use a global.

> 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.

All this to avoid using a global? Especially considering that this will
not work unless you're running as root!
-- 
Peter da Silva.   `-_-'
+1 713 274 5180.   'U`
<peter at ficc.ferranti.com>



More information about the Comp.unix.questions mailing list