Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: Get process name w/o using argv[0] in C function? Message-ID: <3822@auspex.auspex.com> Date: 5 Aug 90 00:54:31 GMT References: <9220003@hpldsla.sid.hp.com> <53103@iuvax.cs.indiana.edu> Organization: Auspex Systems, Santa Clara Lines: 23 >One reason one may not be able to use a global is >if the function that needs the process name >may be a library that is linked in. One way of >accomplishing the goal (though inefficient) is >to do a getpid(2), and then do a popen(3) with >an argument of "ps -p pid ..." Which won't work if your "ps" doesn't support the "-p" option. Another way of accomplishing the goal is to change the library routine (your posting sure assumes the user is in a position to do that; if they can't change the library routine, they sure can't make it do the "getpid()" nor the "popen()") to either: 1) take the "process name" as an argument; 2) have another routine that the main program calls, with the "process name" as an argument, that sets some static variable; 3) assume a (horrors!) global. These require a change to the library interface, but hey, there's no such thing as a free lunch....