home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2870 / user.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-28  |  3.3 KB  |  130 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[] = "@(#)user.c    1.2    22:55:41    2/21/91";
  14. #endif
  15.  
  16. #include <sys/param.h>
  17. #include <sys/sysmacros.h>
  18. #include <sys/types.h>
  19. #include <sys/page.h>
  20. #include <sys/seg.h>
  21. #include <sys/file.h>
  22. #include <sys/proc.h>
  23. #include <sys/signal.h>
  24. #include <sys/dir.h>
  25. #include <sys/user.h>
  26. #include <sys/var.h>
  27. #include <sys/lock.h>
  28. #include "crash.h"
  29.  
  30. findu (proc, slot, user)
  31. struct    proc    *proc;
  32. int    slot;
  33. struct    user    *user;
  34. {
  35.     struct    proc    *procs = (struct proc *) namelist[NM_PROC].xl_value;
  36.     long    swapaddr;
  37.     int    i;
  38.  
  39.     if ((proc->p_flag & (SSWAP|SSPART)) || ! (proc->p_flag & SLOAD)) {
  40.         swapaddr = proc->p_addr[0].te_frameno * NBPC;
  41.         l_lseek (swapfd, swapaddr, 0);
  42.         r_read (swapfd, user, sizeof *user);
  43.     } else {
  44.         l_lseek (memfd, proc->p_addr[0].te_frameno * NBPC, 0);
  45.         r_read (memfd, user, sizeof *user);
  46.     }
  47.     if (user->u_procp - procs == slot)
  48.         return (1);
  49.     else
  50.         return (0);
  51. }
  52.  
  53. prusers (items, cnt)
  54. int    *items;
  55. int    cnt;
  56. {
  57.     int    i;
  58.  
  59.     if (cnt == 0) {
  60.         douser (-1);
  61.         return (1);
  62.     }
  63.     for (i = 0;i < cnt;i++) {
  64.         if (items[i] >= v.v_proc) {
  65.             printf ("value (%d) out of range\n", items[i]);
  66.             continue;
  67.         } else {
  68.             douser (items[i]);
  69.         }
  70.     }
  71. }
  72.  
  73. douser (i)
  74. {
  75.     struct    file    *fp;
  76.     struct    proc    proc;
  77.     struct    proc    *pp;
  78.     static    char    *segments[] = { "user", "system", "user i" };
  79.     int    fileno;
  80.  
  81.     pp = (struct proc *) namelist[NM_PROC].xl_value;
  82.     fp = (struct file *) namelist[NM_FILE].xl_value;
  83.  
  84.     if (i >= 0) {
  85.         l_lseek (kmemfd, (long) &pp[i], 0);
  86.         r_read (kmemfd, &proc, sizeof proc);
  87.  
  88.         if (! findu (&proc, i, &user))
  89.             return (0);
  90.     } else {
  91.         l_lseek (kmemfd, namelist[NM_USER].xl_value, 0);
  92.         r_read (kmemfd, &user, sizeof user);
  93.     }
  94.     printf ("PER PROCESS USER AREA:\n");
  95.     printf ("USER ID's:    uid: %d, gid: %d, real uid: %d, real gid: %d\n",
  96.         user.u_uid, user.u_gid, user.u_ruid, user.u_rgid);
  97.     printf ("PROCESS TIMES:    user: %d, sys: %d, child user: %d, child sys: %d\n",
  98.         user.u_utime, user.u_stime, user.u_cutime, user.u_cstime);
  99.     printf ("PROCESS MISC:    proc slot: %d, cntrl tty: maj(%d) min(%d)\n",
  100.         user.u_procp - pp, major (user.u_ttyd), minor (user.u_ttyd));
  101.     printf ("IPC:        locks:%s%s%s%s%s\n",
  102.         user.u_lock == UNLOCK ? " unlocked":"",
  103.         user.u_lock & PROCLOCK ? " proc":"",
  104.         user.u_lock & TXTLOCK ? " text":"",
  105.         user.u_lock & DATLOCK ? " data":"",
  106.         user.u_lock & HUGELOCK ? " huge":"");
  107.     printf ("FILE I/O:    user addr: %ld, file offset: %ld, bytes: %ld,\n",
  108.         user.u_baseu, user.u_offset, user.u_count);
  109.     printf ("        segment: %s, umask: %01o, ulimit: %ld\n",
  110.         segments[user.u_segflg], user.u_cmask, user.u_limit);
  111.     printf ("ACCOUNTING:    command: %s, memory: %ld, type: %s\n",
  112.         user.u_comm, user.u_mem, user.u_acflag ? "fork":"exec");
  113.     printf ("        start: %s",
  114.         ctime (&user.u_start));
  115.  
  116.     printf ("OPEN FILES:    file desc:  ");
  117.     for (i = 0;i < NOFILE;i++)
  118.         if (user.u_ofile[i] != (struct file *) 0)
  119.             printf ("%4d", i);
  120.     putchar ('\n');
  121.     
  122.     printf ("        file slot:  ");
  123.     for (i = 0;i < NOFILE;i++)
  124.         if (user.u_ofile[i] != (struct file *) 0)
  125.             printf ("%4d", user.u_ofile[i] - fp);
  126.     putchar ('\n');
  127.  
  128.     return (0);
  129. }
  130.