home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2870 / procs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-28  |  2.4 KB  |  107 lines

  1. /*
  2.  * Copyright 1988, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Permission is granted to copy and create derivative works for any
  6.  * non-commercial purpose, provided this copyright notice is preserved
  7.  * in all copies of source code, or included in human readable form
  8.  * and conspicuously displayed on all copies of object code or
  9.  * distribution media.
  10.  */
  11.  
  12. #ifndef    lint
  13. static    char    sccsid[] = "@(#)procs.c    1.2    22:55:38    2/21/91";
  14. #endif
  15.  
  16. #include <sys/param.h>
  17. #include <sys/sysmacros.h>
  18. #include <sys/types.h>
  19. #include <sys/var.h>
  20. #include <sys/text.h>
  21. #include <sys/page.h>
  22. #include <sys/seg.h>
  23. #include <sys/proc.h>
  24. #include <sys/signal.h>
  25. #include <sys/dir.h>
  26. #include <sys/user.h>
  27. #include "crash.h"
  28.  
  29. /*
  30.  * prprocs - output the process table
  31.  */
  32.  
  33. prprocs (items, cnt)
  34. int    *items;
  35. int    cnt;
  36. {
  37.     struct    proc    *pp;
  38.     struct    user    user;
  39.     int    i;
  40.  
  41.     procs = (struct proc *) malloc (v.v_proc * sizeof (struct proc));
  42.     lseek (kmemfd, namelist[NM_PROC].xl_value, 0);
  43.     read (kmemfd, procs, sizeof (struct proc) * v.v_proc);
  44.  
  45.     printf ("SLT ST  PID  PPID  PGRP   UID  EUID PRI CPU    EVENT NAME       FLAGS\n");
  46.  
  47.     if (cnt == 0) {
  48.         for (i = 0;i < v.v_proc;i++) {
  49.             if (procs[i].p_stat == 0)
  50.                 continue;
  51.  
  52.             doproc (i);
  53.         }
  54.     } else {
  55.         for (i = 0;i < cnt;i++) {
  56.             if (items[i] >= v.v_proc)
  57.                 printf ("value (%d) out of range\n", items[i]);
  58.             else
  59.                 doproc (items[i]);
  60.         }
  61.     }
  62.     free ((char *) procs);
  63. }
  64.  
  65. doproc (i)
  66. int    i;
  67. {
  68.     struct    proc    *pp;
  69.  
  70.     pp = &procs[i];
  71.  
  72.     printf ("%3d %c %5d %5d %5d %5d %5d %3d %3d", i,
  73.         " swriztBST"[pp->p_stat], pp->p_pid, pp->p_ppid,
  74.         pp->p_pgrp, pp->p_uid, pp->p_suid,
  75.         pp->p_pri & 0377, pp->p_cpu & 0377);
  76.  
  77.     if (pp->p_wchan)
  78.         printf (" %8x", pp->p_wchan);
  79.     else
  80.         printf ("         ");
  81.  
  82.     if (pp->p_stat == SZOMB) {
  83.         printf (" ZOMBIE    ");
  84.     } else if (pp->p_flag & SSYS) {
  85.         printf (" swapper   ");
  86.     } else if (pp->p_stat != 0) {
  87.         if (findu (pp, i, &user))
  88.             printf (" %-10.10s", user.u_comm);
  89.         else
  90.             printf (" SWAPPED   ");
  91.     } else {
  92.         printf ("           ");
  93.     }
  94.     if (pp->p_stat == SRUN)        printf (" running");
  95.     if (pp->p_stat == SZOMB)    printf (" zombie");
  96.     if (pp->p_flag & SLOAD)        printf (" incore");
  97.     else                printf (" swapped");
  98.     if (pp->p_flag & SSYS)        printf (" sched");
  99.     if (pp->p_flag & SLOCK)        printf (" locked");
  100.     if (pp->p_flag & STRC)        printf (" traced");
  101.     if (pp->p_flag & SWTED)        printf (" wanted");
  102.     if (pp->p_flag & STEXT)        printf (" text");
  103.     if (pp->p_flag & SSPART)    printf (" part-swap");
  104.  
  105.     printf ("\n");
  106. }
  107.