home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3298 / printpstat.c < prev    next >
C/C++ Source or Header  |  1991-05-06  |  2KB  |  117 lines

  1. /* History:
  2. 5/1/91 DJB baseline public domain
  3. */
  4.  
  5. /*
  6.  
  7. char *printpstat(p) struct proc *p; returns a string representing
  8. various basic information about p's status (with p in user memory).
  9. Not well defined.
  10.  
  11. */
  12.  
  13. #include <stdio.h>
  14. #include <strings.h>
  15. #include "printpstat.h"
  16. #include "structproc.h"
  17. #include "confhavepflag.h"
  18.  
  19. static char result[300];
  20. /* XXX: 300 is guaranteed safe for the current code, but if you add */
  21. /* more printing flags, you may have to bring the number up. */
  22.  
  23. char *printpstat(p)
  24. struct proc *p;
  25. {
  26.  int pstat;
  27.  int pflag;
  28.  char *t;
  29.  
  30.  pstat = p->p_stat;
  31. #ifndef HAVE_PFLAG
  32.  pflag = p->p_select | p->p_sched | p->p_vm; /*XXX: annoying*/
  33. #else
  34.  pflag = p->p_flag;
  35. #endif
  36.  
  37.  switch(pstat)
  38.   {
  39. #ifdef SSLEEP
  40.    case SSLEEP: strcpy(result,"S "); break;
  41. #endif
  42. #ifdef SWAIT
  43.    case SWAIT: strcpy(result,"D "); break;
  44. #endif
  45. #ifdef SRUN
  46.    case SRUN: strcpy(result,"R "); break;
  47. #endif
  48. #ifdef SIDL
  49.    case SIDL: strcpy(result,"X "); break;
  50. #endif
  51. #ifdef SZOMB
  52.    case SZOMB: strcpy(result,"Z "); break;
  53. #endif
  54. #ifdef SSTOP
  55.    case SSTOP: strcpy(result,"T "); break;
  56. #endif
  57.    default: strcpy(result,"? ");
  58.   }
  59.  t = result + 2;
  60.  
  61. #define PFLAG(S,X) if (pflag & S) { strcpy(t,X); t += strlen(t); pflag &= ~S; }
  62.  
  63. #ifdef SLOAD
  64.  PFLAG(SLOAD,"load ")
  65. #endif
  66. #ifdef SSYS
  67.  PFLAG(SSYS,"sys ")
  68. #endif
  69. #ifdef SLOCK
  70.  PFLAG(SLOCK,"lock ")
  71. #endif
  72. #ifdef SSWAP
  73.  PFLAG(SSWAP,"swap ")
  74. #endif
  75. #ifdef SOMASK
  76.  PFLAG(SOMASK,"omask ")
  77. #endif
  78. #ifdef SWEXIT
  79.  PFLAG(SWEXIT,"wexit ")
  80. #endif
  81. #ifdef SWTED
  82.  PFLAG(SWTED,"wted ")
  83. #endif
  84. #ifdef SULOCK
  85.  PFLAG(SULOCK,"ulock ")
  86. #endif
  87. #ifdef STRC
  88.  PFLAG(STRC,"traced ")
  89. #endif
  90. #ifdef SPAGI
  91.  PFLAG(SPAGI,"ipage ")
  92. #endif
  93. #ifdef SSEL
  94.  PFLAG(SSEL,"sel! ")
  95. #endif
  96. #ifdef SPTECHG
  97.  PFLAG(SPTECHG,"ptechg ")
  98. #endif
  99. #ifdef SEXECDN
  100.  PFLAG(SEXECDN,"execdn ")
  101. #endif
  102. #ifdef SVFORK
  103.  PFLAG(SVFORK,"vfork ")
  104. #endif
  105. #ifdef SVFDONE
  106.  PFLAG(SVFDONE,"vfdone ")
  107. #endif
  108. #ifdef SNOVM
  109.  PFLAG(SNOVM,"novm ")
  110. #endif
  111.  if (pflag)
  112.   {
  113.    sprintf(t,"flag %x ",pflag);
  114.   }
  115.  return result;
  116. }
  117.