home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / hp / 12695 < prev    next >
Encoding:
Text File  |  1992-11-09  |  2.3 KB  |  94 lines

  1. 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
  2. From: tml@tik.vtt.fi (Tor Lillqvist)
  3. Newsgroups: comp.sys.hp
  4. Subject: Re: Writing to argv[] for display in 'ps'
  5. Date: 9 Nov 92 14:08:55
  6. Organization: Technical Research Centre of Finland, Laboratory for Information
  7.     Processing (VTT/TIK)
  8. Lines: 80
  9. Message-ID: <TML.92Nov9140855@tiuhti.tik.vtt.fi>
  10. References: <1992Nov9.101145.10528@icaen.uiowa.edu>
  11. NNTP-Posting-Host: tiuhti.tik.vtt.fi
  12. In-reply-to: dsiebert@icaen.uiowa.edu's message of Mon, 9 Nov 1992 10:11:45 GMT
  13.  
  14. In article <1992Nov9.101145.10528@icaen.uiowa.edu> dsiebert@icaen.uiowa.edu (Doug Siebert) writes:
  15.  
  16.    How can I write to the argv[] strings in a program so that the
  17.    altered strings show up in 'ps'?
  18.  
  19. In HP-UX you can't do it by clobbering the argv strings, but with the
  20. undocumented pstat syscall.  This code is from sendmail 5.65c. Modify
  21. to your taste (especially remove the " (sendmail)").
  22.  
  23. /*
  24. **  SETPROCTITLE -- set process title for ps
  25. **
  26. **    Parameters:
  27. **        fmt -- a printf style format string.
  28. **        a, b, c -- possible parameters to fmt.
  29. **
  30. **    Returns:
  31. **        none.
  32. **
  33. **    Side Effects:
  34. **        Clobbers argv of our main procedure so ps(1) will
  35. **        display the title.
  36. */
  37.  
  38. /*VARARGS1*/
  39. void
  40. #ifdef __STDC__
  41. setproctitle(const char *fmt, ...)
  42. #else /* !__STDC__ */
  43. setproctitle(fmt, va_alist)
  44.     const char *fmt;
  45. va_dcl
  46. #endif /* __STDC__ */
  47. {
  48. #if defined(SETPROCTITLE) && !defined(SYSV)
  49.     va_list    args;
  50.     register char *p;
  51.     register int i;
  52. #if defined(__hpux) && defined(PSTAT_SETCMD)
  53.     union pstun un;
  54. #else
  55.     extern char **Argv;
  56.     extern char *LastArgv;
  57. #endif
  58.     char buf[MAXLINE];
  59.  
  60. # ifdef __STDC__
  61.     va_start(args, fmt);
  62. # else /* !__STDC__ */
  63.     va_start(args);
  64. # endif /* __STDC__ */
  65.     (void) vsprintf(buf, fmt, args);
  66.     va_end(args);
  67.  
  68. #if defined(__hpux) && defined(PSTAT_SETCMD)
  69.     (void) sprintf(buf + strlen(buf), " (sendmail)");
  70.     un.pst_command = buf;
  71.     pstat(PSTAT_SETCMD, un, strlen(buf), 0, 0);
  72. #else
  73.     /* make ps print "(sendmail)" */
  74.     p = Argv[0];
  75.     *p++ = '-';
  76.  
  77.     i = strlen(buf);
  78.     if (i > LastArgv - p - 2)
  79.     {
  80.         i = LastArgv - p - 2;
  81.         buf[i] = '\0';
  82.     }
  83.     (void) strcpy(p, buf);
  84.     p += i;
  85.     while (p < LastArgv)
  86.         *p++ = ' ';
  87. #endif
  88. #endif /* SETPROCTITLE && !SYSV */
  89. }
  90. --
  91. Tor Lillqvist,
  92. working, but not speaking, for the Technical Research Centre of Finland,
  93. Laboratory for Information Processing (VTT/TIK).
  94.