Get process name w/o using argv[0] in C function?
Scott Barman
scott at nbc1.ge.com
Sat Aug 4 15:18:27 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?
>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 cannot think of one rational or even irrational reason *not* to use
global variables. Can you explain this to us?
Do yourself a favor, declare and global like:
char *progname;
and the first line in your program do:
progname = argv[0];
and save yourself a lot of unnecessary problem--including the waste in
CPU time and disk access trying to read the proc table for something
that is just handed to you. Then again, if you are running a Cray... :-)
--
scott barman NBC Systems Development
scott at nbc1.ge.com 30 Rockerfeller Plaza, Room 1615W
{philabs,crdgw1}!nbc1!scott New York, NY 10112 +1 212/664-2787
(This does not represent any [un]official opinions of NBC or its affiliates)
More information about the Comp.unix.questions
mailing list