* 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.3 (Berkeley) %G%";
static struct nlist nlst
[] = {
static WINDOW
*wload
; /* one line window for load average */
if (p
== (struct cmdtab
*)-1) {
fprintf(stderr
, "%s: unknown request\n",
if (nlst
[X_CCPU
].n_type
== 0) {
fprintf(stderr
, "Couldn't namelist /vmunix.\n");
kmem
= open(kmemf
, O_RDONLY
);
mem
= open(memf
, O_RDONLY
);
swap
= open(swapf
, O_RDONLY
);
* 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
));
lseek(kmem
, nlst
[X_CCPU
].n_value
, L_SET
);
read(kmem
, &ccpu
, sizeof (ccpu
));
hz
= getw(nlst
[X_HZ
].n_value
);
phz
= getw(nlst
[X_PHZ
].n_value
);
curcmd
->c_flags
|= CF_INIT
;
known
[0].k_name
[0] = '\0';
strcpy(procs
[0].cmd
, "<idle>");
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. */
lseek(kmem
, nlst
[X_AVENRUN
].n_value
, L_SET
);
read(kmem
, avenrun
, sizeof (avenrun
));
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
)
lseek(kmem
, nlst
[X_AVENRUN
].n_value
, L_SET
);
read(kmem
, avenrun
, sizeof (avenrun
));
mvprintw(CMDLINE
, 0, "%4.1f %4.1f %4.1f",
avenrun
[0], avenrun
[1], avenrun
[2]);
mvprintw(CMDLINE
, 0, fmt
, a1
, a2
, a3
);