From: katsu@sran14.sra.co.jp (WATANABE katsuhiro)
Newsgroups: fj.sys.news,fj.unix
Subject: Re: Q. about /etc/pstat
Date: 15 Sep 92 09:41:00 GMT
        <9215@icsts1.osaka-u.ac.jp> <9217@icsts1.osaka-u.ac.jp>
Followup-To: fj.unix
Organization: Software Research Associates, Inc.,Japan
In-reply-to: saitoh@icsts1.osaka-u.ac.jp's message of 7 Sep 92 04:51:54 GMT

$B!J(BFollowup-To: $B$KCm0U!K(B
$B!!%U%)%m!<$NCY$5$G$O(B jp $BFb$G==;X$KF~$kEOn4!w#S#R#A$G$9!#(B

$B5-;v(B <IMAGE.92Aug13161150@anavrin.cs.titech.ac.jp> $B$G(B
image@cs.titech.ac.jp (Takashi Imaizumi) $B$5$s$$$O$/(B
> $BEl9)Bg$N:#@t$G$9(B$B!#(B
>       NEWS-OS 4.1$B$G(B /etc/pstat -T $B$r<B9T$9$k$H!"(Btext$B$K4X$9$k=PNO$,(B
>                49/ 98 texts active,  98 used
>       $B$J$I$H$J$C$F?t;z$,(B3$B$D=P$FMh$^$9!#$3$N:G8e$N?t;z$N0UL#$,J,$+$i(B
>       $B$J$$$N(B$B$G$9$,!"$*65$(4j$($J$$$G$7$g$&$+(B?
$B!!(B
$B!!7kO@$r$$$&$H!"#3$DL\$N(B used $B$H$$$&$N$O!"M-8z$J(B vnode $B$H4XO"$E$$(B$B$F$$$k(B
$B%F%-%9%H%F!<%V%k%(%s%H%j!<$N?t$G$9!#(B

$B5-;v(B <9217@icsts1.osaka-u.ac.jp> $B$G(B
saitoh@icsts1.osaka-u.ac.jp (SAITOH Akinori) $B$5$s$$$O$/(B
> $B$I$&$d$C$?$i3N$+$a$i$l$k$s$G$7$g$&$M(B??

$B!!(Bpstat -T $B$O!"(Bpstat -f, -i, -p, -x, -s $B3F!9$N@hF,9T$K=P$k%5%^%j!<$r(B
$BI=<($7$F$$$k$N$HF1$8$G$9$+$i!"(Bpstat -T $B$G2?$i$+$N5?5A$,(B$B@8$8$?$J$i!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j!<%j%9%H$N(B
$B@hF,$K$O$$$o$f$k(B Least Recent Used $B$J%(%s%H%j!<$,$/$k(B$B$N$,L@$i$+$G$"$k!#(B

$B!!(Bprocess file $B$N(B sticky bit(cf. chmod(2))$B$,N)$C$F$$$k>l9g$O!"Nc30E*$K(B
$B%U%j!<%j%9(B$B%H$K@\B3$5$l$J$$!#(B
$B!!$7$?$,$C$F!"$3$l$K2C$($F(B process file $B$N(B vnode $B$,(B rnode $B$H7k$SIU$$$F(B
$B$$$k$N$G$O$J(B$B$$!J$D$^$j(B NFS $B%^%&%s%H@h$K$"$k$o$1$G$O$J$$!K>l9g$K$O!"(B
$B!J$h$7$s$P%F!<%V%k$,0lGU$K$J$C$F$b!KFbMF$,<N$F(B$B$i$l$?$j!"B>$N%F%-%9%HMQ$K(B
$B;H$$2s$5$l$k$h$&$J$3$H$O$J$$!#(B
$B!!(Brnode $B$H7k$SIU$$$F$$$k$H!"!J#3!K$G=R$Y$k$h(B$B$&$JM}M3$+$i!"(Bsticky bit $B$,(B
$BN)$C$F$$$k$K$b$+$+$o$i$::FMxMQ$5$l$F$7$^$&$3$H$,5/$-$&$k!#(B

$B!J#3!K%U%j!<$J(B$B%(%s%H%j!<$H(B vnode $B$H$N4X78(B
[local case]$B!!%U%j!<%j%9%HCf$N%(%s%H%j!<!J%U%j!<$J%(%s%H%j!<!K(B"ft" $B$,(B
vnode $B$r2p$7$F(B in core $B$N(B inode "in" $B$H4X78$7$F$$$k$H$9$k!#$3$N>uBV$G$O(B
in $B$O;2>H%+%&%s%H$,(B 0 $B$G$J$/!"(Binode $B$N%U%j!<%j%9%H$K$O$D$J$,$l$F$$$J$$!#(B
$B!!$$$^!"!JB>$N%F%-%9%H$KMxMQ$5$l$k$?$a!K(Bft $B$NFbMF$,<N$F$i$l$k(B$B$H$9$k$H!"(B
$BBP1~$7$F$$$?(B inode $B$b$I$3$+$i$b;2>H$5$l$J$/$J$k2DG=@-$,$"$j!"$=$&$7$?(B
$B>l9g%U%j!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&%'%"9)3X8&5f=j(B

-------- $B$A$g$-$A$g$-(B -------- $B$A$g$-$A$g$-(B --------
# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by sran14!katsu on Tue Sep 15 18:34:45 JST 1992
# Contents:  README textf.c texts
 
echo x - README
sed 's/^@//' > "README" <<'@//E*O*F README//'

$B%^%K%e%"%k$J$/$F$4$a$s$J$5$$!#$3$l$i$N%W%m%0%i%`$OJ#<L!"2~JQ!":FG[I[$J$I(B$B$,(B
$B<+M3$G$9!#%3%a%s%HEy$r4?7^$7$^$9!#(B--- $BEOn49n9((B <katsu@sra.co.jp>

$B!&(Btextf         $B%F%-%9%H%F!<%V%k(B$B$N%U%j!<%j%9%H$r@hF,$+$iKvHx$K8~$+$C$F(B
                $B$?$I$k%W%m%0%i%`!#(B/dev/kmem $B$N(B read $B$N8"8B$,$J(B$B$1$l$P$J$i$J$$!#(B
                RISC NEWS $B$G$O!"%3%s%Q%$%k;~$K(B -lmld $B$r;XDj$7$F$/$@$5$$!#(B
$B!&(Btexts         pstat -x $B$N3F%(%s%H%j!<$r!"%3%^%s%IL>(B (process file) $B$d(B
                $B%U%!%$%kL>$HBP1~$E$1$k%W(B$B%m%0%i%`!#(B


[texts $B$N;H$$J}MWLs(B]
$B$3$N%W%m%0%i%`$G40A4$KBP1~$D$/$o$1$G$O$"$j$^$;$s!#L\0B!"$"$k$$$O<B83(B$BMQ(B
$B$0$i$$$K9M$($F$/$@$5$$!#Bt;3%W%m%;%9$r5/F0$9$k$N$GCY$$$7!";~4V:9$+$i(B
$BL7=b$7$?>pJs$,=P$k$3$H$b$"$j$^(B$B$9!#(B

$BF0$+$9$H!";2>H?t(B > 1 $B$N%(%s%H%j!<$O$3$s$J$U$&$K=P$^$9!#(B
$B!J(BCADDR $B$+$i!"(Bpstat -p, ps -c $B$r;H$C$F(B PID, COMMAND $BL>$rF@$k!K(B
     LOC    CADDR     VPTR CNT CCNT   PID COMMAND
80162470 8015494c 8013d1d0   1    1     1 init

$B;2>H?t(B > 1 $B$J$s$@$1$I!"%3%"Fb$N%W%m%;%9$+$i$N;2>H?t(B = 0$B!J$D$^$j$3$N%F%-%9%H(B
$B$r;2(B$B>H$7$F$$$kA4$F$N%W%m%;%9$,%9%o%C%W%"%&%H$7$F$$$k!K$@$H!"<!$N$h$&$K(B
$B%3%^%s%IL>$,(B [ ] $B$G0O$^$l$F=P$^$9!#(B
$B!J(BLOC $B$+$i(B pstat -p, ps -c $B$r;H$C$F(B PID, COMMAND $BL>$rF@$k!K(B
80162668        0 8043390c   1    0 24419 [selserv]

$B;2>H?t(B = 0 $B$G!"%-%c%C%7%e$H$7$F!"$"$k$$$O(B sticky bit $B$N1F6A$G;D$C$F$$$k(B
$B$b$N$O!"%3%^%s%I(B$B%U%!%$%k$,$"$k%G%P%$%9$N(B major dev number, minor dev number
$B$*$h$S!"(Binode $B$rAH$K$7$F<!$N$h$&$K=P$^$9!#(B
$B!J(BVPTR $B$+$i(B inode $B$N%"%I%l%9$r7W;;$7!"(Bpstat -i $B$r;H$C$F(B inode $B$rF@$k!K(B
80162b00        0 8013eac0   0    0       (0,5 12674)
$B$A$J$_$K$3$N5!3#$G!"(Bmajor dev=0, minor dev=5 $B$O2?$+$H$$$&$H!"(B
brw-------   1 root     staff      0,   5 Jul 12 20:24 /dev/sd00f
$B$H$$$&$3$H$K$J$C$F$$$F!"$5$i$K(B df /dev/sd00f $B$9$k(B$B$H!"(B
/dev/sd00f             54806   47839     4226     92%   /usr
$B$@$+$i%^%&%s%H%]%$%s%H$,(B /usr $B$G$9$,(B$B!"(Bfind /usr -xdev -inum 12674 -ls
$B$J$I$H$7$F$_$F(B
 12674   64 -rwxr-xr-x   1 root     staff       65536 Mar 17 12:39 /usr/lib/atrun
$B$rF@$k$N$G!"$3$N%(%s%H%j!<$O(B atrun $B$KBP1~$7$F$$$k$H$$$($^$9!#(B

$B!!$^$?!"(B
80163190        0 8043ad0c   0    0       ()
$B$_$?$$$K6u$NL>A0$,=P$F$-$?$i!";2>H?t%<%m$J$,$i$b%-%c%C%7(B$B%e$H$7$F;D$C$F$O(B
$B$$$k$s$@$1$I!"BP1~$9$k(B vnode $B$K$O(B inode $B$G$J$$$b$N$,BP1~$E$$$F$$$?(B
$B!J$D$^$j$O!"B?J,(B NFS $B%^%&%s%H@h$K$"$k%3%^%s%I$r<B9T$7$?;D3<!K$?$a$K!"(B
$B$U$D!<$N%f!<%6!<$K$O%3%^%s%IL>$,$o$+$i$J$+$C$?$H(B$B9M$($F$/$@$5$$!#(B

$B!!$"$H!"(Btext $B$KBP1~$9$k%U%!%$%k$,(B dev no $B$H(B inode $B$N?t;z$NAH$G=P$k$N$O(B
$B$o$+$j$K$/$$(B$B$H$$$&?M$O!"$"$i$+$8$a(B /tmp/.inodetext $B$H$$$&(B "(dev no, inode)"
$B$+$i%U%!%$%kL>$X$NBP1~I=$r:n$C$F$*$1$P(B$B!"(B
80162b00        0 8013eac0   0    0       (atrun)
$B$N$h$&$K(B inode $B$+$i%U%!%$%kL>$r0z$+$;$F$3$l$rI=<((B$B$5$;$k$3$H$,$G$-$^$9!#(B
$B$3$NBP1~I=$r:n$k$K$O!"(B-i $B%9%$%C%A$K0z$-B3$$$F!"BP1~I=$r:n$C$F$*$-$?$$(B
$B%G%#%9%/(B$B%Q!<%F%#%7%g%s$N%^%&%s%H%]%$%s%H$r;XDj$7$^$9!#(B
$B!!Nc$($P!"0lHV:G=i$K(B texts -i / /usr $B$N$h$&$J$3$H$r$d$C(B$B$F$*$/$H$h$$$G$7$g$&!#(B

$B!!(B/tmp/.inodetext $B$OB>?M$K8+$i$l$?$/$J$$%G%#%l%/%H%j!<Fb$N>pJs$bJ];}$7$F(B
$B$7$^(B$B$&$3$H$,$"$j$^$9$N$GCm0U!#(B

@//E*O*F README//
chmod u=rw,g=r,o=r README
 
echo x - textf.c
sed 's/^@//' > "textf.c" <<'@//E*O*F textf.c//'
/*
  List free text table entry of 4.3BSD.
  Written by WATANABE katsuhiro <katsu@sra.co.jp>
  Free to copy, modify, redistribute and so on.
  
  You will need access permission to read /dev/kmem.

  $Id: textf.c,v 2.1 1992/09/15 06:55:44 katsu Exp $
*/

#include <stdio.h>
#include <nlist.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/text.h>

#define KERNELFILE "/vmunix"
#define CORE "/dev/kmem"
#define ktou(kernelp) ((caddr_t)(kernelp) - ((caddr_t)text - (caddr_t)text_copy))
#define utok(userp) ((caddr_t)(userp) + ((caddr_t)text - (caddr_t)text_copy))

#define E_MALLOC 11
#define E_OPEN 12
#define E_NLISTGET 21
#define E_GETKERNVALUE 22

off_t lseek();
char *malloc();

caddr_t mcopy();
int print_tent();

struct text *text, *text_copy, *xhead, *xtail;
int ntext;

/* ARGSUSED */
main(argc, argv)
int argc;
char **argv;
{
    readtextt();
    printf("     LOC     FORW     BACK    CADDR     VPTR CNT CCNT\n");
    traverse_free(xhead, print_tent);
    exit(0);
}

traverse_free(freelist, whattodo)
struct text *freelist;  /* addr in kernel vm space */
int (*whattodo)();
{
    for (; freelist != (struct text *)NULL;
         freelist = ((struct text *)ktou(freelist))->x_forw) {
        if ((*whattodo)(freelist) == 0)
            return;
    }
}

int print_tent(ktent)
struct text *ktent;     /* addr in kernel vm space */
{
    struct text *tent = (struct text *)ktou(ktent);
    
    printf("%8lx %8lx %8lx %8lx %8lx %3d %4d\n",
           (long)ktent,
           (long)tent->x_forw, (long)tent->x_back,
           (long)tent->x_caddr, (long)tent->x_vptr,
           tent->x_count, tent->x_ccount);
    return (-1);
}

readtextt()
{
    static struct nlist namelist[] = {
#define STEXT 0
        {"_text"},
#define SNTEXT 1
        {"_ntext"},
#define SXHEAD 2
        {"_xhead"},
#define SXTAIL 3
        {"_xtail"},
        {""}
    };
    int corefd;
    struct text **textp, **xheadp, **xtailp;
    int *ntextp;
    unsigned texttsize;

    if (nlist(KERNELFILE, namelist) != 0)
        error(E_NLISTGET);
    if ((corefd = open(CORE, O_RDONLY)) < 0)
        error(E_OPEN, CORE);

    textp = (struct text **)namelist[STEXT].n_value;
    if (mcopy(&text, sizeof(text), corefd, (off_t)textp) == (caddr_t)(-1))
        error(E_GETKERNVALUE, "_text");
    ntextp = (int *)(namelist[SNTEXT].n_value);
    if (mcopy(&ntext, sizeof(ntext), corefd, (off_t)ntextp) == (caddr_t)(-1))
        error(E_GETKERNVALUE, "_ntext");
    xheadp = (struct text **)(namelist[SXHEAD].n_value);
    if (mcopy(&xhead, sizeof(xhead), corefd, (off_t)xheadp) == (caddr_t)(-1))
        error(E_GETKERNVALUE, "_xhead");
    xtailp = (struct text **)(namelist[SXTAIL].n_value);
    if (mcopy(&xtail, sizeof(xtail), corefd, (off_t)xtailp) == (caddr_t)(-1))
        error(E_GETKERNVALUE, "_xtail");
    texttsize = sizeof(struct text) * ntext;
    text_copy = (struct text *)malloc(texttsize);
    if (text_copy == (struct text *)NULL)
        error(E_MALLOC);
    if (mcopy(text_copy, (int)texttsize, corefd, (off_t)text) == (caddr_t)(-1))
        error(E_GETKERNVALUE, "text table");
    close(corefd);
}

/*
  a mock mmap().
*/
caddr_t mcopy(addr, len, fd, off)
caddr_t addr;   /* destination */
int len;
int fd;         /* file descriptor */
off_t off;      /* source */
{
    if (lseek(fd, off, L_SET) != off)
        return (caddr_t)(-1);
    if (read(fd, addr, len) < len)
        return (caddr_t)(-1);
    return (addr);
}

/* VARARGS1 */
error(no, str)
int no;
char *str;
{
    switch (no) {
    case 0:
        break;
    case E_MALLOC:
        fprintf(stderr, "cannot allocate memory.\n");
        break;
    case E_OPEN:
        fprintf(stderr, "cannot open %s.\n", str);
        break;
    case E_NLISTGET:
        fprintf(stderr, "cannot get name list.\n");
        break;
    case E_GETKERNVALUE:
        fprintf(stderr, "cannot get kernel value (%s)\n", str);
        break;
    default:
        fprintf(stderr, "error.(%d)\n", no);
    }
    exit(no);
}
@//E*O*F textf.c//
chmod u=rw,g=r,o=r textf.c
 
echo x - texts
sed 's/^@//' > "texts" <<'@//E*O*F texts//'
#!/usr/local/bin/perl
#
#       Print text table and conjecture command name.
#       Written by WATANABE katsuhiro <katsu@sra.co.jp>
#       Free to copy, modify, redistribute and so on.
#       $Id: texts,v 2.1 1992/09/15 08:36:01 katsu Exp $


$ilistfile="/tmp/.inodetext";   # (dev,inum) to name database
$ENV{'PATH'}.='/etc:/usr/etc:'; # Where can I find ps and pstat?

# candidates of init's path 
# (They are used to guess real value of $vnodetoinode.)
push(@initid, &getinodeid("/etc/init"));
push(@initid, &getinodeid("/sbin/init"));
push(@initid, &getinodeid("/usr/etc/init"));

# The offset of inode from top of vnode. (if cannot figure out later)
$vnodetoinode = (-8);


require('getopts.pl');
&Getopts('i');
if ($opt_i) {
        # make inode-to-name database
        &read_ilistdb;
        foreach (@ARGV) {
                ($dev) = stat($_);
                ($dmaj, $dmin) = &device_majorminor($dev);
                open(find, "find $_ -xdev -type f \\( -perm -100 -o -perm -010 -o -perm -001 \\) -ls |") || die "Cannot make inode database for $_";
                while (<find>) {
                        ($inum, $dsize, $mode, $links, $owner, $group, $size,
                        $mon, $date, $year, $path) = split(' ');
                        (@links) = split(/\//, $path);
                        $inode2text{"$dmaj,$dmin $inum"} = $links[$#links];
                }
                close(find);
        }
        open(ilist, ">$ilistfile") || die "Cannot write inode database";
        while (($inodeid, $name) = each %inode2text) {
                print ilist "$inodeid $name\n";
        }
        close(ilist);
        chmod 0666, $ilistfile;
        exit 0;
}

$pspid = open(ps, "-|") || exec 'ps','agxc';
# $command{$pspid} = "ps";
while (<ps>) {
        @fields = split(' ');   # It can happen that STAT field has a space.
        $pid = $fields[$[];
        $command = $fields[$#fields];
        $command{$pid} = $command;
}
close(ps);

$pstatppid = open(pstat, "-|") || exec 'pstat', '-p';
$command{$pstatppid}='pstat';
<pstat>; <pstat>;
while (<pstat>) {
        ($loc, $s, $f, $poip, $pri, $sig, $uid, $slp, $tim, $cpu, $ni, $pgrp,
        $pid, $ppid, $addr, $rss, $srss, $size, $wchan, $link, $textp) =
                split;
        $textp2pid{&kadradj(hex($textp))} = $pid;
        $ploc2pid{hex($loc)} = $pid;
        if ($pid == 1) {
                $inittextp = &kadradj(hex($textp));
        }
}
close(pstat);

$pstatipid = open(pstat, "-|") || exec 'pstat','-i';
$command{$pstatipid} = "pstat";
<pstat>; <pstat>;
undef $initinodep;
while (<pstat>) {
        s/,/ /;
        $iloc = substr($_, 0, 8);
        $idev = substr($_, 15, 7);
        ($ino) = split(' ', substr($_, 22));
        ($idevmaj, $idevmin) = split(' ', $idev);
        $inodeid = "${idevmaj},${idevmin} $ino";
        $inode{hex($iloc)} = $inodeid;
        foreach $initid (@initid) {
                if ($initid eq $inodeid) {
                        $flags = substr($_, 55, 6);
                        if ($flags =~ /T/) {
                                $initinodep = hex($iloc);
                        }
                }
        }
}
close(pstat);

&read_ilistdb;

$pstatxpid = open(pstat, "-|") || exec 'pstat', '-x';
$command{$pstatxpid}='pstat';
$summary = <pstat>;
<pstat>;
print $summary;
print "     LOC    CADDR     VPTR CNT CCNT   PID COMMAND\n";

# try to guess $vnodetoinode
while (<pstat>) {
        push(@pstatx, $_);
        ($loc, $_) = split(/ /, $_, 2);
        s/^[^\da-f]+//;
        ($daddr, $caddr, $rss, $size, $vptr, $cnt, $ccnt, $forw, $back) =
                split;
        if (defined($initinodep) && (hex($loc) == $inittextp)) {
                $vnodetoinode = $initinodep - hex($vptr);
                last;
        }
}

foreach (@pstatx, <pstat>) {
        ($loc, $_) = split(/ /, $_, 2);
        s/^[^\da-f]+//;
        ($daddr, $caddr, $rss, $size, $vptr, $cnt, $ccnt, $forw, $back) =
                split;
        
        printf("%8s %8s %8s %3d %4d", $loc, $caddr, $vptr, $cnt, $ccnt);
        if (defined($pid = $ploc2pid{hex($caddr)})) {
                # resident in core
                printf(" %5d %s", $pid, $command{$pid});
        } elsif ($pid = $textp2pid{hex($loc)}) {
                # swapped
                printf(" %5d [%s]", $pid, $command{$pid});
        } elsif ($vptr) {
                # cache
                $inode = $inode{hex($vptr) + $vnodetoinode};
                if ($text = $inode2text{$inode}) {
                        print "       ($text)";
                } else {
                        print "       ($inode)";
                }
        } else {
                # free (no vnode)
        }
        print "\n";
}
close(pstat);

sub kadradj {
        local($msb_cleaned_addr) = @_;
        $msb_cleaned_addr + 0x80000000; 
}

# stat(filename) and make a string like "$maj_dev,$minor_dev $inum".
sub getinodeid {
        local($filename) = @_;
        ($dev, $ino, $mode) = stat($filename);  
        ($dmaj, $dmin) = &device_majorminor($dev); 
        "${dmaj},${dmin} $ino";
}

# divide device number into (major num , minor num)
sub device_majorminor {
        local($device) = @_;
        ($dev >> 8, $dev & 0xff);
}

# read $ilistfile database into %inode2text
sub read_ilistdb {
        local($ilist, $device, $inode, $name);
        if (open(ilist, "$ilistfile")) {
                while (<ilist>) {
                        ($device, $inode, $name) = split;       
                        $inode2text{"$device $inode"} = $name;
                }
                close(ilist);
        }
}
@//E*O*F texts//
chmod u=rwx,g=rx,o=rx texts
 
exit 0