root@pigs.UUCP (Joe Bob Willie) (07/20/88)
Posting-number: Volume 3, Issue 93 Submitted-by: "Joe Bob Willie" <root@pigs.UUCP> Archive-name: psc here is yet another submission. we've been having so much trouble with our plexus computers that i've written a utility to format the contents of the u-page in the core dumps we are getting. [Somehow that sounds familiar.... ++bsa this command reads the user structure from a core file and outputs it in a format similiar to what crash produces. this has already proved to be a handy little tool. - john. ------------------------------- cut here ------------------------ #! /bin/sh echo x - psc.c sed 's/^X//' << \EOF > psc.c X#include <sys/types.h> X#include <sys/sysmacros.h> X#include <sys/param.h> X#include <sys/signal.h> X#include <sys/dir.h> X#include <sys/file.h> X#include <sys/proc.h> X#include <sys/lock.h> X#include <sys/user.h> X#include <stdio.h> X X/* X * psc - print status from core file X * X * This program was written by John F. Haugh II, and is hereby X * placed in the public domain. Use at your own risk ... X * X * Author: X * X * John F. Haugh II (jfh@rpp386.uucp) X * 19 July 1988 X * X * Synopsis: X * X * psc [ corefile ] X * X * Description: X * X * psc reads the user page from the beginning of a core file and X * outputs some statistics. The format is fairly similiar to the X * output produced by the `user' command in crash(1M). Note that X * the I/O information is generally worthless since Unix sets X * up a write command to output the core file. X * X * If corefile is omitted, psc defaults to the file named core in X * the current directory. X * X * To Port: X * X * The u-page is the first structure starting at the beginning X * of the core file. This should be universally true for all AT&T X * Unixii and may be true for Berzerkeley Unix. The only thing X * which may need to be changed is the u_base member of the user X * structure. Look in /usr/include/sys/user.h for possible names X * for the base address for I/O. X * X * The other big change has to do with the appropriate collection X * of include files. There are dozens of possibilities. But, X * fortunately only a finite number of combinations. X * X * To Compile: X * X * cc -o psc psc.c X */ X Xstruct user user; Xchar *corefile = "core"; X Xmain (argc, argv) Xint argc; Xchar **argv; X{ X char *segments[] = { "user", "system", "user i" }; X FILE *cfp; X X if (argc != 0) X corefile = argv[1]; X X if ((cfp = fopen (corefile, "r")) == (FILE *) 0) { X perror (corefile); X exit (1); X } X if (fread ((char *) &user, sizeof user, 1, cfp) != 1) { X perror (corefile); X exit (1); X } X printf ("PER PROCESS USER AREA:\n"); X printf ("USER ID's: uid: %d, gid: %d, real uid: %d, real gid: %d\n", X user.u_uid, user.u_gid, user.u_ruid, user.u_rgid); X printf ("PROCESS TIMES: user: %d, sys: %d, child user: %d, child sys: %d\n", X user.u_utime, user.u_stime, user.u_cutime, user.u_cstime); X printf ("PROCESS MISC: proc slot: %lx, cntrl tty: maj(%d) min(%d)\n", X user.u_procp, major (user.u_ttyd), minor (user.u_ttyd)); X printf ("IPC: locks:%s%s%s%s%s\n", X user.u_lock == UNLOCK ? " unlocked":"", X user.u_lock & PROCLOCK ? " proc":"", X user.u_lock & TXTLOCK ? " text":"", X user.u_lock & DATLOCK ? " data":""); X printf ("FILE I/O: user addr: %ld, file offset: %ld, bytes: %ld,\n", X#if defined(M_XENIX) X user.u_baseu, X#else X user.u_base, X#endif X user.u_offset, user.u_count); X printf (" segment: %s, umask: %01o, ulimit: %ld\n", X segments[user.u_segflg], user.u_cmask, user.u_limit); X printf ("ACCOUNTING: command: %s, memory: %ld, type: %s\n", X user.u_comm, user.u_mem, user.u_acflag ? "fork":"exec"); X printf (" start: %s", X ctime (&user.u_start)); X} EOF exit 0