Operating System - HP-UX
1833848 Members
2174 Online
110063 Solutions
New Discussion

Printing process name in Shared lib function

 
Sup
Advisor

Printing process name in Shared lib function

Hi,

I have 3 functions calling single function
present in shared lib. I want to print these
process names in the shared lib function.

Is there any system call to get process name?

Thanx in Advance
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor

Re: Printing process name in Shared lib function

Depending upon the compiler/linker you use a global variable is set. Man crt0 for details.

The scheme is this:

extern char **__argv_value;
/* yours may be __argv */


.....
.....
(void) printf("Process: %s\n",__argv_value[0]);
---------------------------------------------
A far mode portable method is to do a getpid() and then a popen() call to ps -p pid.
If it ain't broke, I can fix that.
Klaus Crusius
Trusted Contributor

Re: Printing process name in Shared lib function

Define another function initname(const char*)for the shared library, which you call at the beginning of main( .... argv) { initname(argv[0]); ...

char* processname;
void initname(const char* name ) {
processname = name;
}

you can access processname in all (shared) functions.

Thanks,
Klaus
There is a live before death!
Klaus Crusius
Trusted Contributor

Re: Printing process name in Shared lib function

assigning points to the replies is as easy as reading them, at least easier than providing the answers.
There is a live before death!