Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!snorkelwacker!spdcc!merk!alliant!linus!philabs!nbc1!scott From: scott@nbc1.ge.com (Scott Barman) Newsgroups: comp.unix.questions Subject: Re: Get process name w/o using argv[0] in C function? Message-ID: <1990Aug4.051827.16438@nbc1.ge.com> Date: 4 Aug 90 05:18:27 GMT References: <9220003@hpldsla.sid.hp.com> Reply-To: scott@nbc1.GE.COM (Scott Barman) Organization: National Broadcasting Company, Inc., New York Lines: 26 In article <9220003@hpldsla.sid.hp.com> manoj@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@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)