* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.10 (Berkeley) %G%";
static struct nlist nlst
[] = {
void die(), display(), suspend();
static WINDOW
*wload
; /* one line window for load average */
int verbose
= 1; /* to report kvm read errs */
if (p
== (struct cmdtab
*)-1) {
fprintf(stderr
, "%s: unknown request\n",
if (nlst
[X_FIRST
].n_type
== 0) {
fprintf(stderr
, "Couldn't namelist.\n");
* Initialize display. Load average appears in a one line
* window of its own. Current command's display appears in
* an overlapping sub-window of stdscr configured by the display
* routines to minimize update work by curses.
wnd
= (*curcmd
->c_open
)();
fprintf(stderr
, "Couldn't initialize display.\n");
wload
= newwin(1, 0, 3, 20);
fprintf(stderr
, "Couldn't set up load average window.\n");
gethostname(hostname
, sizeof (hostname
));
NREAD(X_PHZ
, &phz
, LONG
);
curcmd
->c_flags
|= CF_INIT
;
signal(SIGALRM
, display
);
sigtstpdfl
= signal(SIGTSTP
, suspend
);
if (curcmd
->c_flags
& CF_LOADAV
) {
"/0 /1 /2 /3 /4 /5 /6 /7 /8 /9 /10");
mvaddstr(3, 5, "Load Average");
mvprintw(21, 25, "CPU usage on %s", hostname
);
/* Get the load average over the last minute. */
(void) getloadavg(avenrun
, sizeof(avenrun
) / sizeof(avenrun
[0]));
if (curcmd
->c_flags
& CF_LOADAV
) {
j
= 5.0*avenrun
[0] + 0.5;
wmove(wload
, 0, 0); wclrtoeol(wload
);
for (i
= (j
> 50) ? 50 : j
; i
> 0; i
--)
wprintw(wload
, " %4.1f", avenrun
[0]);
if (curcmd
->c_flags
& CF_LOADAV
)
(void) getloadavg(avenrun
, sizeof(avenrun
)/sizeof(avenrun
[0]));
mvprintw(CMDLINE
, 0, "%4.1f %4.1f %4.1f",
avenrun
[0], avenrun
[1], avenrun
[2]);
fmt
= va_arg(ap
, char *);
(void) vsnprintf(msg
, sizeof msg
, fmt
, ap
);
mvaddstr(CMDLINE
, 0, msg
);