home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!ames!saimiri.primate.wisc.edu!tik.vtt.fi!tik.vtt.fi!tml
- From: tml@tik.vtt.fi (Tor Lillqvist)
- Newsgroups: comp.sys.hp
- Subject: Re: Writing to argv[] for display in 'ps'
- Date: 9 Nov 92 14:08:55
- Organization: Technical Research Centre of Finland, Laboratory for Information
- Processing (VTT/TIK)
- Lines: 80
- Message-ID: <TML.92Nov9140855@tiuhti.tik.vtt.fi>
- References: <1992Nov9.101145.10528@icaen.uiowa.edu>
- NNTP-Posting-Host: tiuhti.tik.vtt.fi
- In-reply-to: dsiebert@icaen.uiowa.edu's message of Mon, 9 Nov 1992 10:11:45 GMT
-
- In article <1992Nov9.101145.10528@icaen.uiowa.edu> dsiebert@icaen.uiowa.edu (Doug Siebert) writes:
-
- How can I write to the argv[] strings in a program so that the
- altered strings show up in 'ps'?
-
- In HP-UX you can't do it by clobbering the argv strings, but with the
- undocumented pstat syscall. This code is from sendmail 5.65c. Modify
- to your taste (especially remove the " (sendmail)").
-
- /*
- ** SETPROCTITLE -- set process title for ps
- **
- ** Parameters:
- ** fmt -- a printf style format string.
- ** a, b, c -- possible parameters to fmt.
- **
- ** Returns:
- ** none.
- **
- ** Side Effects:
- ** Clobbers argv of our main procedure so ps(1) will
- ** display the title.
- */
-
- /*VARARGS1*/
- void
- #ifdef __STDC__
- setproctitle(const char *fmt, ...)
- #else /* !__STDC__ */
- setproctitle(fmt, va_alist)
- const char *fmt;
- va_dcl
- #endif /* __STDC__ */
- {
- #if defined(SETPROCTITLE) && !defined(SYSV)
- va_list args;
- register char *p;
- register int i;
- #if defined(__hpux) && defined(PSTAT_SETCMD)
- union pstun un;
- #else
- extern char **Argv;
- extern char *LastArgv;
- #endif
- char buf[MAXLINE];
-
- # ifdef __STDC__
- va_start(args, fmt);
- # else /* !__STDC__ */
- va_start(args);
- # endif /* __STDC__ */
- (void) vsprintf(buf, fmt, args);
- va_end(args);
-
- #if defined(__hpux) && defined(PSTAT_SETCMD)
- (void) sprintf(buf + strlen(buf), " (sendmail)");
- un.pst_command = buf;
- pstat(PSTAT_SETCMD, un, strlen(buf), 0, 0);
- #else
- /* make ps print "(sendmail)" */
- p = Argv[0];
- *p++ = '-';
-
- i = strlen(buf);
- if (i > LastArgv - p - 2)
- {
- i = LastArgv - p - 2;
- buf[i] = '\0';
- }
- (void) strcpy(p, buf);
- p += i;
- while (p < LastArgv)
- *p++ = ' ';
- #endif
- #endif /* SETPROCTITLE && !SYSV */
- }
- --
- Tor Lillqvist,
- working, but not speaking, for the Technical Research Centre of Finland,
- Laboratory for Information Processing (VTT/TIK).
-