static char *sccsid
= "@(#)pstat.c 4.4 (Berkeley) %G%";
#define clear(x) ((int)x&0x7fffffff)
char *fcore
= "/dev/kmem";
char *fnlist
= "/vmunix";
while (argc
> 0 && **argv
== '-') {
sscanf( *argv
++, "%x", &ubase
);
if ((fc
= open(fcore
, 0)) < 0) {
printf("Can't find %s\n", fcore
);
register struct nlist
*nlp
;
for (nlp
=nl
; nlp
< &nl
[sizeof (nl
)/sizeof(nl
[0])]; nlp
++)
nlp
->n_value
= clear(nlp
->n_value
);
usrpt
= (struct pte
*)nl
[USRPT
].n_value
;
Usrptma
= (struct pte
*)nl
[USRPTMA
].n_value
;
register struct inode
*ip
;
struct inode xinode
[NINODE
];
lseek(fc
, (long)nl
[SINODE
].n_value
, 0);
read(fc
, xinode
, sizeof(xinode
));
for (ip
= xinode
; ip
< &xinode
[NINODE
]; ip
++)
printf("%3d/%3d inodes\n", nin
, NINODE
);
printf("%d/%d active xinodes\n", nin
, NINODE
);
printf(" LOC FLAGS CNT DEVICE INO MODE NLK UID SIZE/DEV\n");
loc
= nl
[SINODE
].n_value
;
for (ip
= xinode
; ip
< &xinode
[NINODE
]; ip
++, loc
+= sizeof(xinode
[0])) {
putf(ip
->i_flag
&ILOCK
, 'L');
putf(ip
->i_flag
&IUPD
, 'U');
putf(ip
->i_flag
&IACC
, 'A');
putf(ip
->i_flag
&IMOUNT
, 'M');
putf(ip
->i_flag
&IWANT
, 'W');
putf(ip
->i_flag
&ITEXT
, 'T');
printf("%4d", ip
->i_count
&0377);
printf("%4d,%3d", major(ip
->i_dev
), minor(ip
->i_dev
));
printf("%6d", ip
->i_number
);
printf("%6x", ip
->i_mode
& 0xffff);
printf("%4d", ip
->i_nlink
);
printf("%4d", ip
->i_uid
);
if ((ip
->i_mode
&IFMT
)==IFBLK
|| (ip
->i_mode
&IFMT
)==IFCHR
)
printf("%6d,%3d", major(ip
->i_un
.i_rdev
), minor(ip
->i_un
.i_rdev
));
printf("%10ld", ip
->i_size
);
register struct text
*xp
;
struct text xtext
[NTEXT
];
lseek(fc
, (long)nl
[STEXT
].n_value
, 0);
read(fc
, xtext
, sizeof(xtext
));
for (xp
= xtext
; xp
< &xtext
[NTEXT
]; xp
++)
printf("%3d/%3d texts\n", ntx
, NTEXT
);
printf(" LOC FLAGS DADDR CADDR RSS SIZE IPTR CNT CCNT\n");
for (xp
= xtext
; xp
< &xtext
[NTEXT
]; xp
++, loc
+=sizeof(xtext
[0])) {
putf(xp
->x_flag
&XPAGI
, 'P');
putf(xp
->x_flag
&XTRC
, 'T');
putf(xp
->x_flag
&XWRIT
, 'W');
putf(xp
->x_flag
&XLOAD
, 'L');
putf(xp
->x_flag
&XLOCK
, 'K');
putf(xp
->x_flag
&XWANT
, 'w');
printf("%5x", xp
->x_daddr
[0]);
printf("%11x", xp
->x_caddr
);
printf("%5d", xp
->x_rssize
);
printf("%5d", xp
->x_size
);
printf("%10.1x", xp
->x_iptr
);
printf("%5d", xp
->x_count
&0377);
printf("%5d", xp
->x_ccount
);
struct proc xproc
[NPROC
];
register struct proc
*pp
;
lseek(fc
, (long)nl
[SPROC
].n_value
, 0);
read(fc
, xproc
, sizeof(xproc
));
for (pp
=xproc
; pp
< &xproc
[NPROC
]; pp
++)
printf("%3d/%3d processes\n", np
, NPROC
);
printf("%d/%d processes\n", np
, NPROC
);
printf(" LOC S F POIP PRI SIG UID SLP TIM CPU NI PGRP PID PPID ADDR RSS SRSS SIZE WCHAN LINK TEXTP CLKT\n");
for (loc
=nl
[SPROC
].n_value
,pp
=xproc
; pp
<&xproc
[NPROC
]; pp
++,loc
+=sizeof(xproc
[0])) {
if (pp
->p_stat
==0 && allflg
==0)
printf(" %2d", pp
->p_stat
);
printf(" %4x", pp
->p_flag
& 0xffff);
printf(" %4d", pp
->p_poip
);
printf(" %3d", pp
->p_pri
);
printf(" %8x", pp
->p_sig
);
printf(" %4d", pp
->p_uid
);
printf(" %3d", pp
->p_slptime
);
printf(" %3d", pp
->p_time
);
printf(" %4d", pp
->p_cpu
&0377);
printf(" %3d", pp
->p_nice
);
printf(" %6d", pp
->p_pgrp
);
printf(" %6d", pp
->p_pid
);
printf(" %6d", pp
->p_ppid
);
pp
->p_addr
= (struct pte
*)clear((int)pp
->p_addr
);
lseek(fc
, (long)(Usrptma
+btokmx(pp
->p_addr
)), 0);
read(fc
, &apte
, sizeof(apte
));
printf(" %8x", ctob(apte
.pg_pfnum
+1) - sizeof(struct pte
) * UPAGES
);
printf(" %4x", pp
->p_rssize
);
printf(" %4x", pp
->p_swrss
);
printf(" %5x", pp
->p_dsize
+pp
->p_ssize
);
printf(" %7x", clear(pp
->p_wchan
));
printf(" %7x", clear(pp
->p_link
));
printf(" %7x", clear(pp
->p_textp
));
printf(" %u", pp
->p_clktim
);
lseek(fc
, (long)nl
[SKL
].n_value
, 0);
read(fc
, dz_tty
, sizeof(dz_tty
[0]));
mesg
= " # RAW CAN OUT MODE ADDR DEL COL STATE PGRP DISC\n";
if (nl
[SNDZ
].n_type
== 0)
lseek(fc
, (long)nl
[SNDZ
].n_value
, 0);
read(fc
, &ndz
, sizeof(ndz
));
printf("%d dz lines\n", ndz
);
lseek(fc
, (long)nl
[SDZ
].n_value
, 0);
read(fc
, dz_tty
, sizeof(dz_tty
));
for (tp
= dz_tty
; tp
< &dz_tty
[ndz
]; tp
++)
if (nl
[SNDH
].n_type
== 0)
lseek(fc
, (long)nl
[SNDH
].n_value
, 0);
read(fc
, &ndz
, sizeof(ndz
));
printf("%d dh lines\n", ndz
);
lseek(fc
, (long)nl
[SDH
].n_value
, 0);
read(fc
, dz_tty
, sizeof(dz_tty
));
for (tp
= dz_tty
; tp
< &dz_tty
[ndz
]; tp
++)
printf("%4d%4d", 0, tp
->t_inbuf
);
printf("%4d%4d", tp
->t_inbuf
, 0);
printf("%4d", tp
->t_rawq
.c_cc
);
printf("%4d", tp
->t_canq
.c_cc
);
printf("%4d", tp
->t_outq
.c_cc
);
printf("%8.1o", tp
->t_flags
);
printf(" %8.1x", tp
->t_addr
);
printf("%3d", tp
->t_delct
);
printf("%4d ", tp
->t_col
);
putf(tp
->t_state
&TIMEOUT
, 'T');
putf(tp
->t_state
&WOPEN
, 'W');
putf(tp
->t_state
&ISOPEN
, 'O');
putf(tp
->t_state
&CARR_ON
, 'C');
putf(tp
->t_state
&BUSY
, 'B');
putf(tp
->t_state
&ASLEEP
, 'A');
putf(tp
->t_state
&XCLUDE
, 'X');
putf(tp->t_state&HUPCLS, 'H');
printf("%6d", tp
->t_pgrp
);
/* This wins only if PAGSIZ > sizeof (struct user) */
lseek(fc
, ubase
* NBPG
, 0);
while (ip
< &U
.u_arg
[0]) {
if ((ip
- (int *)&U
.u_pcb
) % 4 == 0)
if ((ip
- (int *)&U
.u_pcb
) % 4 == 0)
if ((ip
- (int *)&U
.u_pcb
) % 4 != 0)
printf(" %.1x", U
.u_arg
[i
]);
for (i
=0; i
<sizeof(label_t
)/sizeof(int); i
++) {
printf("%9.1x", U
.u_ssav
[i
]);
printf("segflg\t%d\nerror %d\n", U
.u_segflg
, U
.u_error
);
printf("uids\t%d,%d,%d,%d\n", U
.u_uid
,U
.u_gid
,U
.u_ruid
,U
.u_rgid
);
printf("procp\t%.1x\n", U
.u_procp
);
printf("ap\t%.1x\n", U
.u_ap
);
printf("r_val?\t%.1x %.1x\n", U
.u_r
.r_val1
, U
.u_r
.r_val2
);
printf("base, count, offset %.1x %.1x %ld\n", U
.u_base
,
printf("cdir rdir %.1x %.1x\n", U
.u_cdir
, U
.u_rdir
);
printf("dbuf %.14s\n", U
.u_dbuf
);
printf("dirp %.1x\n", U
.u_dirp
);
printf("dent %d %.14s\n", U
.u_dent
.d_ino
, U
.u_dent
.d_name
);
printf("pdir %.1o\n", U
.u_pdir
);
printf("%9.1x", U
.u_ofile
[i
]);
for (i
=10; i
<NOFILE
; i
++)
printf("%9.1x", U
.u_ofile
[i
]);
printf("%9.1x", U
.u_pofile
[i
]);
for (i
=10; i
<NOFILE
; i
++)
printf("%9.1x", U
.u_pofile
[i
]);
for (i
=0; i
<sizeof(label_t
)/sizeof(int); i
++) {
printf("%9.1x", U
.u_ssav
[i
]);
printf("%.1x ", U
.u_signal
[i
]);
printf("cfcode\t%.1x\n", U
.u_cfcode
);
printf("ar0\t%.1x\n", U
.u_ar0
);
printf("prof\t%X %X %X %X\n", U
.u_prof
.pr_base
, U
.u_prof
.pr_size
,
U
.u_prof
.pr_off
, U
.u_prof
.pr_scale
);
printf("\neosys\t%d\n", U
.u_eosys
);
printf("sep\t%d\n", U
.u_sep
);
printf("ttyp\t%.1x\n", U
.u_ttyp
);
printf("ttyd\t%d,%d\n", major(U
.u_ttyd
), minor(U
.u_ttyd
));
printf("comm %.14s\n", U
.u_comm
);
printf("start\t%D\n", U
.u_start
);
printf("acflag\t%D\n", U
.u_acflag
);
printf("fpflag\t%D\n", U
.u_fpflag
);
printf("cmask\t%D\n", U
.u_cmask
);
printf("sizes\t%.1x %.1x %.1x\n", U
.u_tsize
, U
.u_dsize
, U
.u_ssize
);
for (i
= 0; i
< sizeof(U
.u_vm
)/sizeof(int); i
++)
for (i
= 0; i
< sizeof(U
.u_vm
)/sizeof(int); i
++)
printf("%x ", 0140000+2*i);
struct file xfile
[NFILE
];
register struct file
*fp
;
lseek(fc
, (long)nl
[SFIL
].n_value
, 0);
read(fc
, xfile
, sizeof(xfile
));
for (fp
=xfile
; fp
< &xfile
[NFILE
]; fp
++)
printf("%3d/%3d files\n", nf
, NFILE
);
printf("%d/%d open files\n", nf
, NFILE
);
printf(" LOC FLG CNT INO OFFS\n");
for (fp
=xfile
,loc
=nl
[SFIL
].n_value
; fp
< &xfile
[NFILE
]; fp
++,loc
+=sizeof(xfile
[0])) {
putf(fp
->f_flag
&FREAD
, 'R');
putf(fp
->f_flag
&FWRITE
, 'W');
putf(fp
->f_flag
&FPIPE
, 'P');
printf("%4d", mask(fp
->f_count
));
printf("%9.1x", fp
->f_inode
);
printf(" %ld\n", fp
->f_un
.f_offset
);
struct text xtext
[NTEXT
];
struct map swapmap
[SMAPSIZ
];
register struct proc
*pp
;
int nswap
, used
, tused
, free
;
register struct text
*xp
;
lseek(fc
, (long)nl
[SPROC
].n_value
, 0);
read(fc
, proc
, sizeof(proc
));
lseek(fc
, (long)nl
[SWAPMAP
].n_value
, 0);
read(fc
, swapmap
, sizeof(swapmap
));
lseek(fc
, (long)nl
[SNSWAP
].n_value
, 0);
read(fc
, &nswap
, sizeof(nswap
));
for (mp
= swapmap
; mp
< &swapmap
[SMAPSIZ
]; mp
++)
lseek(fc
, (long)nl
[STEXT
].n_value
, 0);
read(fc
, xtext
, sizeof(xtext
));
for (xp
= xtext
; xp
< &xtext
[NTEXT
]; xp
++)
for (pp
= proc
; pp
< &proc
[NPROC
]; pp
++) {
if (pp
->p_stat
== 0 || pp
->p_stat
== SZOMB
)
used
+= up(pp
->p_dsize
) + up(pp
->p_ssize
);
if ((pp
->p_flag
&SLOAD
) == 0)
/* a DMMAX block goes to argmap */
printf("%3d/%3d 00k swap\n", used
/2/100, (used
+free
)/2/100);
printf("%d used (%d text), %d free, %d missing\n",
used
/2, tused
/2, free
/2, (nswap
- DMMAX
- (used
+ free
))/2);
register int tsz
= p
->p_tsize
/ NPTEPG
;
return (clrnd(UPAGES
+ clrnd(ctopt(p
->p_tsize
+p
->p_dsize
+p
->p_ssize
+UPAGES
)) - tsz
));
return (clrnd(xp
->x_size
+ ctopt(xp
->x_size
)));
struct chan chans
[NCHANS
];
struct schan schans
[NPORTS
];
lseek(fc
, (long)nl
[SCHANS
].n_value
, 0);
read(fc
, chans
, sizeof chans
);
lseek(fc
, (long)nl
[SSCHANS
].n_value
, 0);
read(fc
, schans
, sizeof schans
);
printf("CHAN FLAGS INDEX LINE GROUP FILE TTYP CTLX PGRP OTTYP OLINE DATQ CTLY\n");
for (i
= 0; i
< NCHANS
; i
++) {
putf(chans
[i
].c_flags
&INUSE
, 'I');
putf(chans
[i
].c_flags
&SIOCTL
, 'S');
putf(chans
[i
].c_flags
&XGRP
, 'X');
putf(chans
[i
].c_flags
&YGRP
, 'Y');
putf(chans
[i
].c_flags
&WCLOSE
, 'W');
putf(chans
[i
].c_flags
&ISGRP
, 'i');
putf(chans
[i
].c_flags
&BLOCK
, 'B');
putf(chans
[i
].c_flags
&EOTMARK
, 'E');
putf(chans
[i
].c_flags
&SIGBLK
, 's');
putf(chans
[i
].c_flags
&BLKMSG
, 'b');
putf(chans
[i
].c_flags
&ENAMSG
, 'e');
putf(chans
[i
].c_flags
&WFLUSH
, 'w');
putf(chans
[i
].c_flags
&NMBUF
, 'N');
putf(chans
[i
].c_flags
&PORT
, 'P');
putf(chans
[i
].c_flags
&ALT
, 'A');
putf(chans
[i
].c_flags
&FBLOCK
, 'F');
printf("%8x ", chans
[i
].c_index
);
printf("%3d ", chans
[i
].c_line
);
printf("%8x ", chans
[i
].c_group
);
printf("%8x ", chans
[i
].c_fy
);
printf("%8x ", chans
[i
].c_ttyp
);
printf("%8x ", chans
[i
].c_ctlx
);
printf("%6d ", chans
[i
].c_pgrp
);
printf("%8x ", chans
[i
].c_ottyp
);
printf("%3d ", chans
[i
].c_oline
);
printf("%8x ", chans
[i
].cx
.datq
);
printf("%8x\n", chans
[i
].c_ctly
);
printf("\nCHAN FLAGS INDEX LINE GROUP FILE TTYP CTLX PGRP\n");
for (i
= 0; i
< NPORTS
; i
++) {
putf(schans
[i
].c_flags
&INUSE
, 'I');
putf(schans
[i
].c_flags
&SIOCTL
, 'S');
putf(schans
[i
].c_flags
&XGRP
, 'X');
putf(schans
[i
].c_flags
&YGRP
, 'Y');
putf(schans
[i
].c_flags
&WCLOSE
, 'W');
putf(schans
[i
].c_flags
&ISGRP
, 'i');
putf(schans
[i
].c_flags
&BLOCK
, 'B');
putf(schans
[i
].c_flags
&EOTMARK
, 'E');
putf(schans
[i
].c_flags
&SIGBLK
, 's');
putf(schans
[i
].c_flags
&BLKMSG
, 'b');
putf(schans
[i
].c_flags
&ENAMSG
, 'e');
putf(schans
[i
].c_flags
&WFLUSH
, 'w');
putf(schans
[i
].c_flags
&NMBUF
, 'N');
putf(schans
[i
].c_flags
&PORT
, 'P');
putf(schans
[i
].c_flags
&ALT
, 'A');
putf(schans
[i
].c_flags
&FBLOCK
, 'F');
printf("%8x ", schans
[i
].c_index
);
printf("%3d ", schans
[i
].c_line
);
printf("%8x ", schans
[i
].c_group
);
printf("%8x ", schans
[i
].c_fy
);
printf("%8x ", schans
[i
].c_ttyp
);
printf("%8x ", schans
[i
].c_ctlx
);
printf("%6d\n", schans
[i
].c_pgrp
);
struct group
*groups
[NGROUPS
];
lseek(fc
, (long)nl
[SGROUP
].n_value
, 0);
read(fc
, groups
, sizeof groups
);
printf("GROUP STATE INDEX ROT *GROUP *INODE *FILE ROTM DATQ\n");
for (i
= 0; i
< NGROUPS
; i
++) {
lseek(fc
, (long) groups
[i
], 0);
printf("%8x ", g
.g_state
);
printf("%8x ", g
.g_index
);
printf("%8x ", g
.g_group
);
printf("%8x ", g
.g_inode
);
printf("%8x ", g
.g_file
);
printf("%3d ", g
.g_rotmask
);
printf("%3d\n", g
.g_datq
);