* examine and print certain things about processes
while (*ap
) switch (*ap
++) {
fprintf(stderr
, "Can't change to /dev\n");
nlist(argc
>2? argv
[2]:"/unix", nl
);
fprintf(stderr
, "No namelist\n");
if ((mem
= open(coref
, 0)) < 0) {
fprintf(stderr
, "No mem\n");
* read mem to find swap dev.
lseek(mem
, (long)nl
[1].n_value
, 0);
read(mem
, (char *)&nl
[1].n_value
, sizeof(nl
[1].n_value
));
lseek(mem
, (long)nl
[2].n_value
, 0);
read(mem
, (char *)&swplo
, sizeof(swplo
));
lseek(mem
, (long)nl
[0].n_value
, 0);
printf(" F S UID PID PPID CPU PRI NICE ADDR SZ WCHAN TTY TIME CMD\n"); else
if (chkpid
==0) printf(" PID TTY TIME CMD\n");
for (i
=0; i
<NPROC
; i
++) {
read(mem
, (char *)&mproc
, sizeof mproc
);
if (mproc
.p_pgrp
==0 && xflg
==0 && mproc
.p_uid
==0)
if ((uid
!= puid
&& aflg
==0) ||
(chkpid
!=0 && chkpid
!=mproc
.p_pid
))
if ((df
= fopen("/dev", "r")) == NULL
) {
fprintf(stderr
, "Can't open /dev\n");
while (fread((char *)&dbuf
, sizeof(dbuf
), 1, df
) == 1) {
if(stat(dbuf
.d_name
, &sbuf
) < 0)
if ((sbuf
.st_mode
&S_IFMT
) != S_IFCHR
)
strcpy(devl
[ndev
].dname
, dbuf
.d_name
);
devl
[ndev
].dev
= sbuf
.st_rdev
;
if ((swap
= open("/dev/swap", 0)) < 0) {
fprintf(stderr
, "Can't open /dev/swap\n");
long txtsiz
, datsiz
, stksiz
;
if (mproc
.p_flag
&SLOAD
) {
addr
= ctob((long)mproc
.p_addr
);
addr
= (mproc
.p_addr
+swplo
)<<9;
if (read(file
, (char *)&u
, sizeof(u
)) != sizeof(u
))
/* set up address maps for user pcs */
txtsiz
= ctob(u
.u_tsize
);
datsiz
= ctob(u
.u_dsize
);
stksiz
= ctob(u
.u_ssize
);
datmap
.b1
= (septxt
? 0 : round(txtsiz
,TXTRNDSIZ
));
datmap
.e1
= datmap
.b1
+datsiz
;
datmap
.f1
= ctob(USIZE
)+addr
;
datmap
.b2
= stackbas(stksiz
);
datmap
.e2
= stacktop(stksiz
);
datmap
.f2
= ctob(USIZE
)+(datmap
.e1
-datmap
.b1
)+addr
;
if (tptr
&& strncmp(tptr
, tp
, 2))
printf("%2o %c%4d", mproc
.p_flag
,
"0SWRIZT"[mproc
.p_stat
], puid
);
printf("%6u", mproc
.p_pid
);
printf("%6u%4d%4d%5d%6o%4d", mproc
.p_ppid
, mproc
.p_cpu
&0377,
mproc
.p_addr
, (mproc
.p_size
+7)>>3);
printf("%7o", mproc
.p_wchan
);
if (mproc
.p_stat
==SZOMB
) {
tm
= (u
.u_utime
+ u
.u_stime
+ 30)/60;
printf(tm
<10?"0%ld":"%ld", tm
);
if (vflg
&& lflg
==0) { /* 0 == old tflg (print long times) */
tm
= (u
.u_cstime
+ 30)/60;
printf(tm
<10?"0%ld":"%ld", tm
);
tm
= (u
.u_cutime
+ 30)/60;
printf(tm
<10?"0%ld":"%ld", tm
);
addr
+= ctob((long)mproc
.p_size
) - 512;
/* look for sh special */
lseek(file
, addr
+512-sizeof(char **), 0);
if (read(file
, (char *)&ap
, sizeof(char *)) != sizeof(char *))
while((cp
=getptr(ap
++)) && cp
&& (bp
<b
+lw
) ) {
while((c
=getbyte(cp
++)) && (bp
<b
+lw
)) {
printf(lflg
?" %.30s":" %.60s", b
);
if (read(file
, abuf
, sizeof(abuf
)) != sizeof(abuf
))
for (ip
= (int *)&abuf
[512]-2; ip
> (int *)abuf
; ) {
if (*--ip
== -1 || *ip
==0) {
for (cp1
= cp
; cp1
< &abuf
[512]; cp1
++) {
else if (c
< ' ' || c
> 0176) {
while (cp1
>cp
&& *--cp1
!=' ')
printf(lflg
?" %.30s":" %.60s", cp
);
if (devl
[i
].dev
== u
.u_ttyd
) {
if (p
[0]=='t' && p
[1]=='t' && p
[2]=='y')
for (i
=0; i
<sizeof(ptr
); i
++)
register struct map
*amap
= &datmap
;
if(!within(adr
, amap
->b1
, amap
->e1
)) {
if(within(adr
, amap
->b2
, amap
->e2
)) {
saddr
= (unsigned)adr
+ amap
->f2
- amap
->b2
;
saddr
= (unsigned)adr
+ amap
->f1
- amap
->b1
;
if(lseek(file
, saddr
, 0)==-1
|| read(file
, &b
, 1)<1) {
return((unsigned)adr
>=lbd
&& (unsigned)adr
<ubd
);