home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume3 / psc < prev    next >
Internet Message Format  |  1989-02-03  |  4KB

  1. Path: xanth!mcnc!gatech!bloom-beacon!husc6!m2c!necntc!ncoast!allbery
  2. From: root@pigs.UUCP (Joe Bob Willie)
  3. Newsgroups: comp.sources.misc
  4. Subject: v03i093: psc -- format and print the user area of a core file
  5. Message-ID: <8807191526.AA02289@pigs.UUCP>
  6. Date: 19 Jul 88 20:26:28 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: root@pigs.UUCP (Joe Bob Willie)
  9. Lines: 123
  10. Approved: allbery@ncoast.UUCP
  11.  
  12. Posting-number: Volume 3, Issue 93
  13. Submitted-by: "Joe Bob Willie" <root@pigs.UUCP>
  14. Archive-name: psc
  15.  
  16. here is yet another submission.  we've been having so much trouble with
  17. our plexus computers that i've written a utility to format the contents
  18. of the u-page in the core dumps we are getting.
  19.  
  20. [Somehow that sounds familiar....  ++bsa
  21.  
  22. this command reads the user structure from a core file and outputs it in
  23. a format similiar to what crash produces.  this has already proved to be
  24. a handy little tool.
  25.  
  26. - john.
  27. ------------------------------- cut here ------------------------
  28. #! /bin/sh
  29. echo x - psc.c
  30. sed 's/^X//' << \EOF > psc.c
  31. X#include <sys/types.h>
  32. X#include <sys/sysmacros.h>
  33. X#include <sys/param.h>
  34. X#include <sys/signal.h>
  35. X#include <sys/dir.h>
  36. X#include <sys/file.h>
  37. X#include <sys/proc.h>
  38. X#include <sys/lock.h>
  39. X#include <sys/user.h>
  40. X#include <stdio.h>
  41. X
  42. X/*
  43. X * psc - print status from core file
  44. X *
  45. X *    This program was written by John F. Haugh II, and is hereby
  46. X *    placed in the public domain.  Use at your own risk ...
  47. X *
  48. X *    Author:
  49. X *
  50. X *    John F. Haugh II    (jfh@rpp386.uucp)
  51. X *    19 July 1988
  52. X *
  53. X *    Synopsis:
  54. X *
  55. X *    psc [ corefile ]
  56. X *
  57. X *    Description:
  58. X *
  59. X *    psc reads the user page from the beginning of a core file and
  60. X *    outputs some statistics.  The format is fairly similiar to the
  61. X *    output produced by the `user' command in crash(1M).  Note that
  62. X *    the I/O information is generally worthless since Unix sets
  63. X *    up a write command to output the core file.
  64. X *
  65. X *    If corefile is omitted, psc defaults to the file named core in
  66. X *    the current directory.
  67. X *
  68. X *    To Port:
  69. X *
  70. X *    The u-page is the first structure starting at the beginning
  71. X *    of the core file.  This should be universally true for all AT&T
  72. X *    Unixii and may be true for Berzerkeley Unix.  The only thing
  73. X *    which may need to be changed is the u_base member of the user
  74. X *    structure.  Look in /usr/include/sys/user.h for possible names
  75. X *    for the base address for I/O.
  76. X *
  77. X *    The other big change has to do with the appropriate collection
  78. X *    of include files.  There are dozens of possibilities.  But,
  79. X *    fortunately only a finite number of combinations.
  80. X *
  81. X *    To Compile:
  82. X *
  83. X *    cc -o psc psc.c
  84. X */
  85. X
  86. Xstruct    user    user;
  87. Xchar    *corefile = "core";
  88. X
  89. Xmain (argc, argv)
  90. Xint    argc;
  91. Xchar    **argv;
  92. X{
  93. X    char    *segments[] = { "user", "system", "user i" };
  94. X    FILE    *cfp;
  95. X
  96. X    if (argc != 0)
  97. X        corefile = argv[1];
  98. X
  99. X    if ((cfp = fopen (corefile, "r")) == (FILE *) 0) {
  100. X        perror (corefile);
  101. X        exit (1);
  102. X    }
  103. X    if (fread ((char *) &user, sizeof user, 1, cfp) != 1) {
  104. X        perror (corefile);
  105. X        exit (1);
  106. X    }
  107. X    printf ("PER PROCESS USER AREA:\n");
  108. X    printf ("USER ID's:    uid: %d, gid: %d, real uid: %d, real gid: %d\n",
  109. X        user.u_uid, user.u_gid, user.u_ruid, user.u_rgid);
  110. X    printf ("PROCESS TIMES:    user: %d, sys: %d, child user: %d, child sys: %d\n",
  111. X        user.u_utime, user.u_stime, user.u_cutime, user.u_cstime);
  112. X    printf ("PROCESS MISC:    proc slot: %lx, cntrl tty: maj(%d) min(%d)\n",
  113. X        user.u_procp, major (user.u_ttyd), minor (user.u_ttyd));
  114. X    printf ("IPC:        locks:%s%s%s%s%s\n",
  115. X        user.u_lock == UNLOCK ? " unlocked":"",
  116. X        user.u_lock & PROCLOCK ? " proc":"",
  117. X        user.u_lock & TXTLOCK ? " text":"",
  118. X        user.u_lock & DATLOCK ? " data":"");
  119. X    printf ("FILE I/O:    user addr: %ld, file offset: %ld, bytes: %ld,\n",
  120. X#if defined(M_XENIX)
  121. X        user.u_baseu,
  122. X#else
  123. X        user.u_base,
  124. X#endif
  125. X        user.u_offset, user.u_count);
  126. X    printf ("        segment: %s, umask: %01o, ulimit: %ld\n",
  127. X        segments[user.u_segflg], user.u_cmask, user.u_limit);
  128. X    printf ("ACCOUNTING:    command: %s, memory: %ld, type: %s\n",
  129. X        user.u_comm, user.u_mem, user.u_acflag ? "fork":"exec");
  130. X    printf ("        start: %s",
  131. X        ctime (&user.u_start));
  132. X}
  133. EOF
  134. exit 0
  135.