* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)print.c 8.2 (Berkeley) %G%";
#include <sys/resource.h>
static void printval
__P((char*, struct var
*));
register struct varent
*vent
;
for (vent
= vhead
; vent
; vent
= vent
->next
) {
if (vent
->next
== NULL
) /* last one */
(void)printf("%s", v
->header
);
(void)printf("%-*s", v
->width
, v
->header
);
(void)printf("%*s", v
->width
, v
->header
);
extern int termwidth
, totwidth
;
if (termwidth
== UNLIMITED
) {
(void)printf("%s ", k
->ki_env
);
(void)printf("%s", k
->ki_args
);
register int left
= termwidth
- (totwidth
- v
->width
);
if (left
< 1) /* already wrapped, just use std width */
while (--left
>= 0 && *cp
)
while (--left
>= 0 && *cp
)
(void)printf("%-*.*s", v
->width
, v
->width
, k
->ki_args
);
(void)printf("%-*s", v
->width
, KI_PROC(k
)->p_comm
);
(void)printf("%-*s", v
->width
, KI_PROC(k
)->p_logname
);
(void)printf("%-*s", v
->width
, KI_EPROC(k
)->e_login
);
if (flag
& SSINTR
) /* interuptable (long) */
*cp
= p
->p_slptime
>= MAXSLP
? 'I' : 'S';
if (p
->p_rssize
> p
->p_maxrss
)
else if (p
->p_nice
> NZERO
)
if (flag
& SWEXIT
&& p
->p_stat
!= SZOMB
)
if (flag
& (SSYS
|SLOCK
|SKEEP
|SPHYSIO
))
if (flag
& (SSYS
|SLOCK
|SULOCK
|SKEEP
|SPHYSIO
))
if (KI_EPROC(k
)->e_flag
& EPROC_SLEADER
)
if ((flag
& SCTTY
) && KI_EPROC(k
)->e_pgid
== KI_EPROC(k
)->e_tpgid
)
(void)printf("%-*s", v
->width
, buf
);
(void)printf("%*d", v
->width
, KI_PROC(k
)->p_priority
- PZERO
);
(int)v
->width
, user_from_uid(KI_PROC(k
)->p_uid
, 0));
(int)v
->width
, user_from_uid(KI_EPROC(k
)->e_ucred
.cr_uid
, 0));
(int)v
->width
, user_from_uid(KI_PROC(k
)->p_ruid
, 0));
(int)v
->width
, user_from_uid(KI_EPROC(k
)->e_pcred
.p_ruid
, 0));
dev
= KI_EPROC(k
)->e_tdev
;
(void)printf("%*s", v
->width
, "??");
(void)snprintf(buff
, sizeof(buff
),
"%d/%d", major(dev
), minor(dev
));
(void)printf("%*s", v
->width
, buff
);
dev
= KI_EPROC(k
)->e_tdev
;
if (dev
== NODEV
|| (ttname
= devname(dev
, S_IFCHR
)) == NULL
)
(void)printf("%-*s", v
->width
, "??");
if (strncmp(ttname
, "tty", 3) == 0)
(void)printf("%*.*s%c", v
->width
-1, v
->width
-1, ttname
,
KI_EPROC(k
)->e_flag
& EPROC_CTTY
? ' ' : '-');
dev
= KI_EPROC(k
)->e_tdev
;
if (dev
== NODEV
|| (ttname
= devname(dev
, S_IFCHR
)) == NULL
)
(void)printf("%-*s", v
->width
, "??");
(void)printf("%-*s", v
->width
, ttname
);
(void)printf("%-*s", v
->width
, "-");
tp
= localtime(&k
->ki_u
.u_start
.tv_sec
);
if (now
- k
->ki_u
.u_start
.tv_sec
< 24 * SECSPERHOUR
) {
static char fmt
[] = "%l:@M%p";
fmt
[3] = '%'; /* I *hate* SCCS... */
(void)strftime(buf
, sizeof(buf
) - 1, fmt
, tp
);
} else if (now
- k
->ki_u
.u_start
.tv_sec
< 7 * SECSPERDAY
) {
static char fmt
[] = "%a@I%p";
fmt
[2] = '%'; /* I *hate* SCCS... */
(void)strftime(buf
, sizeof(buf
) - 1, fmt
, tp
);
(void)strftime(buf
, sizeof(buf
) - 1, "%e%b%y", tp
);
(void)printf("%-*s", v
->width
, buf
);
(void)printf("%-*s", v
->width
, "-");
(void)strftime(buf
, sizeof(buf
) -1, "%C",
localtime(&k
->ki_u
.u_start
.tv_sec
));
(void)printf("%-*s", v
->width
, buf
);
if (KI_PROC(k
)->p_wchan
) {
(void)printf("%-*.*s", v
->width
, v
->width
,
(void)printf("%-*x", v
->width
,
(int)KI_PROC(k
)->p_wchan
&~ KERNBASE
);
(void)printf("%-*s", v
->width
, "-");
#define pgtok(a) (((a)*NBPG)/1024)
(void)printf("%*d", v
->width
,
pgtok(KI_PROC(k
)->p_dsize
+ KI_PROC(k
)->p_ssize
+ KI_EPROC(k
)->e_xsize
));
pgtok(KI_EPROC(k
)->e_vm
.vm_dsize
+ KI_EPROC(k
)->e_vm
.vm_ssize
+
KI_EPROC(k
)->e_vm
.vm_tsize
));
(void)printf("%*d", v
->width
,
pgtok(KI_PROC(k
)->p_rssize
+ (KI_EPROC(k
)->e_xccount
?
(KI_EPROC(k
)->e_xrssize
/ KI_EPROC(k
)->e_xccount
) : 0)));
/* XXX don't have info about shared */
(void)printf("%*d", v
->width
, pgtok(KI_EPROC(k
)->e_vm
.vm_rssize
));
p_rssize(k
, ve
) /* doesn't account for text */
(void)printf("%*d", v
->width
, pgtok(KI_PROC(k
)->p_rssize
));
(void)printf("%*d", v
->width
, pgtok(KI_EPROC(k
)->e_vm
.vm_rssize
));
long psecs
; /* "parts" of a second. first micro, then centi */
if (KI_PROC(k
)->p_stat
== SZOMB
|| !k
->ki_u
.u_valid
) {
* This counts time spent handling interrupts. We could
* fix this, but it is not 100% trivial (and interrupt
* time fractions only work on the sparc anyway). XXX
secs
= KI_PROC(k
)->p_rtime
.tv_sec
;
psecs
= KI_PROC(k
)->p_rtime
.tv_usec
;
secs
+= k
->ki_u
.u_cru
.ru_utime
.tv_sec
+
k
->ki_u
.u_cru
.ru_stime
.tv_sec
;
psecs
+= k
->ki_u
.u_cru
.ru_utime
.tv_usec
+
k
->ki_u
.u_cru
.ru_stime
.tv_usec
;
* round and scale to 100's
psecs
= (psecs
+ 5000) / 10000;
(void)snprintf(obuff
, sizeof(obuff
),
"%3ld:%02ld.%02ld", secs
/60, secs
%60, psecs
);
(void)printf("%*s", v
->width
, obuff
);
extern int fscale
, nlistread
, rawcpu
;
#define fxtofl(fixpt) ((double)(fixpt) / fscale)
/* XXX - I don't like this */
if (p
->p_swtime
== 0 || (p
->p_flag
& SLOAD
) == 0)
return (100.0 * fxtofl(p
->p_pctcpu
));
return (100.0 * fxtofl(p
->p_pctcpu
) /
(1.0 - exp(p
->p_swtime
* log(fxtofl(ccpu
)))));
(void)printf("%*.1f", v
->width
, getpcpu(k
));
extern int mempages
, nlistread
;
if ((p
->p_flag
& SLOAD
) == 0)
szptudot
= UPAGES
+ clrnd(ctopt(p
->p_dsize
+ p
->p_ssize
+ e
->e_xsize
));
fracmem
= ((float)p
->p_rssize
+ szptudot
)/CLSIZE
/mempages
;
if (p
->p_textp
&& e
->e_xccount
)
fracmem
+= ((float)e
->e_xrssize
)/CLSIZE
/e
->e_xccount
/mempages
;
/* XXX want pmap ptpages, segtab, etc. (per architecture) */
/* XXX don't have info about shared */
fracmem
= ((float)e
->e_vm
.vm_rssize
+ szptudot
)/CLSIZE
/mempages
;
return (100.0 * fracmem
);
(void)printf("%*.1f", v
->width
, getpmem(k
));
(void)printf("%*d", v
->width
,
k
->ki_u
.u_valid
? k
->ki_u
.u_ru
.ru_majflt
: 0);
#ifndef NEWVM /* not yet */
if (KI_PROC(k
)->p_maxrss
!= (RLIM_INFINITY
/NBPG
))
(void)printf("%*d", v
->width
, pgtok(KI_PROC(k
)->p_maxrss
));
(void)printf("%*s", v
->width
, "-");
(void)printf("%*d", v
->width
, pgtok(KI_EPROC(k
)->e_xsize
));
(void)printf("%*d", v
->width
, pgtok(KI_EPROC(k
)->e_vm
.vm_tsize
));
(void)printf("%*d", v
->width
, pgtok(KI_EPROC(k
)->e_xrssize
));
* Generic output routines. Print fields from various prototype
printval((char *)((char *)KI_PROC(k
) + v
->off
), v
);
printval((char *)((char *)KI_EPROC(k
) + v
->off
), v
);
printval((char *)((char *)&k
->ki_u
+ v
->off
), v
);
(void)printf("%*s", v
->width
, "-");
printval((char *)((char *)(&k
->ki_u
.u_ru
) + v
->off
), v
);
(void)printf("%*s", v
->width
, "-");
static char ofmt
[32] = "%";
(void)printf(ofmt
, v
->width
, *(char *)bp
);
(void)printf(ofmt
, v
->width
, *(u_char
*)bp
);
(void)printf(ofmt
, v
->width
, *(short *)bp
);
(void)printf(ofmt
, v
->width
, *(u_short
*)bp
);
(void)printf(ofmt
, v
->width
, *(long *)bp
);
(void)printf(ofmt
, v
->width
, *(u_long
*)bp
);
(void)printf(ofmt
, v
->width
, *(u_long
*)bp
&~ KERNBASE
);
errx(1, "unknown type %d", v
->type
);