Unix Technical Forum

Resetting process name?

This is a discussion on Resetting process name? within the comp.unix.solaris forums, part of the Solaris Operating System category; --> Folks, I have written a set of functions I use to reset the process name of the processes spawn ...


Go Back   Unix Technical Forum > Unix Operating Systems > Solaris Operating System > comp.unix.solaris

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-06-2008, 08:44 AM
Hemant Shah
 
Posts: n/a
Default Resetting process name?


Folks,

I have written a set of functions I use to reset the process name of the
processes spawn by my application. I have found that different OS have
different ways of renaming the process name. I have ported by functions to
AIX, HP-UX, Solaris and Linux. I still have to add few checks for length
of ProcTitle so that I do not get buffer overflow.

Here is the code:
---------cut-------------cut-------------cut-------------cut----
#include <stdio.h>
#include <string.h>

/* Use #define USE_PSTAT for HP
** Use #define RESET_POINTER for AIX and Solaris
** Use nothing for Linux
*/


static char ProcTitle[40];
static char **ArgV0;

void InitProcTitle(char **TheArgV0)
{
ArgV0=TheArgV0;
}

void SetProcTitle(char *NewProcName)
{
#ifdef USE_PSTAT
union pstun un;
strcpy(ProcTitle, NewProcName);
un.pst_command = ProcTitle;
pstat(PSTAT_SETCMD, un, strlen(ProcTitle), 0, 0);
#else
strcpy(ProcTitle, NewProcName);
#ifdef RESET_POINTER
*ArgV0 = ProcTitle;
#else
strcpy(*ArgV0, ProcTitle);
#endif
#endif
}
void AppendProcTitle(char *NewProcExt)
{
#ifdef USE_PSTAT
union pstun un;
strcat(ProcTitle, ".");
strcat(ProcTitle, NewProcExt);
un.pst_command = ProcTitle;
pstat(PSTAT_SETCMD, un, strlen(ProcTitle), 0, 0);
#else
strcat(ProcTitle, ".");
strcat(ProcTitle, NewProcExt);
#ifdef RESET_POINTER
*ArgV0 = ProcTitle;
#else
strcpy(*ArgV0, ProcTitle);
#endif
#endif
}

---------cut-------------cut-------------cut-------------cut----

Here is the sample program to test it.
---------cut-------------cut-------------cut-------------cut----
int main(int argc, char *argv[])
{
char Buffer[80];

InitProcTitle(argv);

SetProcTitle("NewName");

printf("argv[0] = %s\n", argv[0]);

sprintf(Buffer, "ps -ef |grep $LOGNAME");
system(Buffer);

exit(0);
}
---------cut-------------cut-------------cut-------------cut----

This works fine on AIX, HP-UX and Linux using "/bin/ps -eft".
On Solaris I have to use "/usr/ucb/ps auxwwwt" command, /bin/ps will not
show the new name it will display the original name of the executable.

I am worried about Linux since I have to copy new name over argv[0]. I may
corrupt the memory. Does anyone know how big argv[0] is on Linux?

Thanks.




--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:19 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com