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

Guy Harris guy at auspex.auspex.com
Sun Aug 5 10:54:31 AEST 1990


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



More information about the Comp.unix.questions mailing list