* Copyright (c) 1990 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)print.c 5.9 (Berkeley) 7/1/91";
#include <sys/resource.h>
#include <sys/kinfo_proc.h>
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_args
);
register int left
= termwidth
- (totwidth
- v
->width
);
register char *cp
= k
->ki_args
;
if (left
< 1) /* already wrapped, just use std width */
while (--left
>= 0 && *cp
)
(void) printf("%-*.*s", v
->width
, v
->width
, k
->ki_args
);
(void) printf("%-*s", v
->width
, k
->ki_p
->p_comm
);
(void) printf("%-*s", v
->width
, k
->ki_p
->p_logname
);
(void) printf("%-*s", v
->width
, k
->ki_e
->e_login
);
register struct proc
*p
= k
->ki_p
;
register flag
= p
->p_flag
;
if (flag
& SSINTR
) /* interuptable (long) */
*cp
= p
->p_slptime
>= MAXSLP
? 'I' : 'S';
*cp
= (flag
& SPAGE
) ? 'P' : 'D';
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 (k
->ki_e
->e_flag
& EPROC_SLEADER
)
if ((flag
& SCTTY
) && k
->ki_e
->e_pgid
== k
->ki_e
->e_tpgid
)
(void) printf("%-*s", v
->width
, buf
);
(void) printf("%*d", v
->width
, k
->ki_p
->p_pri
- PZERO
);
(void) printf("%-*s", v
->width
, user_from_uid(k
->ki_p
->p_uid
, 0));
(void) printf("%-*s", v
->width
,
user_from_uid(k
->ki_e
->e_ucred
.cr_uid
, 0));
(void) printf("%-*s", v
->width
, user_from_uid(k
->ki_p
->p_ruid
, 0));
(void) printf("%-*s", v
->width
,
user_from_uid(k
->ki_e
->e_pcred
.p_ruid
, 0));
dev_t dev
= k
->ki_e
->e_tdev
;
(void) printf("%*s", v
->width
, "??");
(void) sprintf(buff
, "%d/%d", major(dev
), minor(dev
));
(void) printf("%*s", v
->width
, buff
);
char *ttname
, *devname();
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
,
k
->ki_e
->e_flag
& EPROC_CTTY
? ' ' : '-');
char *ttname
, *devname();
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
);
(void) printf("%-*.*s", v
->width
, v
->width
, k
->ki_e
->e_wmesg
);
(void) printf("%-*x", v
->width
,
(int)k
->ki_p
->p_wchan
&~ KERNBASE
);
(void) printf("%-*s", v
->width
, "-");
#define pgtok(a) (((a)*NBPG)/1024)
(void) printf("%*d", v
->width
,
pgtok(k
->ki_p
->p_dsize
+ k
->ki_p
->p_ssize
+ k
->ki_e
->e_xsize
));
pgtok(k
->ki_e
->e_vm
.vm_dsize
+ k
->ki_e
->e_vm
.vm_ssize
+
k
->ki_e
->e_vm
.vm_tsize
));
(void) printf("%*d", v
->width
,
pgtok(k
->ki_p
->p_rssize
+ (k
->ki_e
->e_xccount
?
(k
->ki_e
->e_xrssize
/ k
->ki_e
->e_xccount
) : 0)));
/* XXX don't have info about shared */
(void) printf("%*d", v
->width
, pgtok(k
->ki_e
->e_vm
.vm_rssize
));
p_rssize(k
, v
) /* doesn't account for text */
(void) printf("%*d", v
->width
, pgtok(k
->ki_p
->p_rssize
));
(void) printf("%*d", v
->width
, pgtok(k
->ki_e
->e_vm
.vm_rssize
));
long psecs
; /* "parts" of a second. first micro, then centi */
if (k
->ki_p
->p_stat
== SZOMB
|| k
->ki_u
== NULL
) {
secs
= k
->ki_p
->p_utime
.tv_sec
+
psecs
= k
->ki_p
->p_utime
.tv_usec
+
k
->ki_p
->p_stime
.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) sprintf(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_time
== 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_time
* 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
? k
->ki_u
->u_ru
.ru_majflt
: 0);
#ifndef NEWVM /* not yet */
if (k
->ki_p
->p_maxrss
!= (RLIM_INFINITY
/NBPG
))
(void) printf("%*d", v
->width
, pgtok(k
->ki_p
->p_maxrss
));
(void) printf("%*s", v
->width
, "-");
(void) printf("%*d", v
->width
, pgtok(k
->ki_e
->e_xsize
));
(void) printf("%*d", v
->width
, pgtok(k
->ki_e
->e_vm
.vm_tsize
));
(void) printf("%*d", v
->width
, pgtok(k
->ki_e
->e_xrssize
));
* Generic output routines. Print fields from various prototype
printval((char *)((char *)k
->ki_p
+ v
->off
), v
);
printval((char *)((char *)k
->ki_e
+ 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] = "%";
register char *cp
= ofmt
+1, *fcp
= v
->fmt
;
(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
);
err("unknown type %d", v
->type
);