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 ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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. |