version 1.61, 2006/11/13 19:03:51 |
version 1.62, 2007/02/25 18:21:24 |
|
|
#include <signal.h> |
#include <signal.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <utmp.h> |
|
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "systat.h" |
#include "systat.h" |
|
|
static float cputime(int); |
static float cputime(int); |
static void dinfo(int, int); |
static void dinfo(int, int); |
static void getinfo(struct Info *); |
static void getinfo(struct Info *); |
static void putint(int, int, int, int); |
void putint(int, int, int, int); |
static void putuint64(u_int64_t, int, int, int); |
void putuint64(u_int64_t, int, int, int); |
static void putfloat(double, int, int, int, int, int); |
void putfloat(double, int, int, int, int, int); |
static int ucount(void); |
int ucount(void); |
|
|
static int ut; |
|
static char buf[26]; |
|
static time_t t; |
static time_t t; |
static double etime; |
static double etime; |
static float hertz; |
static float hertz; |
|
|
static char **intrname; |
static char **intrname; |
static int nextintsrow; |
static int nextintsrow; |
|
|
struct utmp utmp; |
|
|
|
WINDOW * |
WINDOW * |
openkre(void) |
openkre(void) |
{ |
{ |
|
return (subwin(stdscr, LINES-1-1, 0, 1, 0)); |
ut = open(_PATH_UTMP, O_RDONLY); |
|
if (ut < 0) |
|
error("No utmp"); |
|
return (stdscr); |
|
} |
} |
|
|
void |
void |
closekre(WINDOW *w) |
closekre(WINDOW *w) |
{ |
{ |
|
|
(void) close(ut); |
|
if (w == NULL) |
if (w == NULL) |
return; |
return; |
wclear(w); |
wclear(w); |
wrefresh(w); |
wrefresh(w); |
|
delwin(w); |
} |
} |
|
|
|
|
/* |
/* |
* These constants define where the major pieces are laid out |
* These constants define where the major pieces are laid out |
*/ |
*/ |
|
|
void |
void |
fetchkre(void) |
fetchkre(void) |
{ |
{ |
time_t now; |
|
|
|
time(&now); |
|
strlcpy(buf, ctime(&now), sizeof buf); |
|
getinfo(&s); |
getinfo(&s); |
} |
} |
|
|
|
|
{ |
{ |
int i, j, l; |
int i, j, l; |
|
|
clear(); |
|
mvprintw(STATROW, STATCOL + 4, "users Load"); |
|
mvprintw(MEMROW, MEMCOL, " memory totals (in KB)"); |
mvprintw(MEMROW, MEMCOL, " memory totals (in KB)"); |
mvprintw(MEMROW + 1, MEMCOL, " real virtual free"); |
mvprintw(MEMROW + 1, MEMCOL, " real virtual free"); |
mvprintw(MEMROW + 2, MEMCOL, "Active"); |
mvprintw(MEMROW + 2, MEMCOL, "Active"); |
|
|
addch(cpuchar[c]); |
addch(cpuchar[c]); |
} |
} |
|
|
putint(ucount(), STATROW, STATCOL, 3); |
|
putfloat(avenrun[0], STATROW, STATCOL + 17, 6, 2, 0); |
|
putfloat(avenrun[1], STATROW, STATCOL + 23, 6, 2, 0); |
|
putfloat(avenrun[2], STATROW, STATCOL + 29, 6, 2, 0); |
|
mvaddstr(STATROW, STATCOL + 53, buf); |
|
#define pgtokb(pg) ((pg) * (s.uvmexp.pagesize / 1024)) |
#define pgtokb(pg) ((pg) * (s.uvmexp.pagesize / 1024)) |
|
|
putint(pgtokb(s.uvmexp.active), MEMROW + 2, MEMCOL + 7, 8); |
putint(pgtokb(s.uvmexp.active), MEMROW + 2, MEMCOL + 7, 8); |
|
|
return (dkcmd(cmd, args)); |
return (dkcmd(cmd, args)); |
} |
} |
|
|
/* calculate number of users on the system */ |
|
static int |
|
ucount(void) |
|
{ |
|
int nusers = 0; |
|
|
|
if (ut < 0) |
|
return (0); |
|
while (read(ut, &utmp, sizeof(utmp))) |
|
if (utmp.ut_name[0] != '\0') |
|
nusers++; |
|
|
|
lseek(ut, 0, SEEK_SET); |
|
return (nusers); |
|
} |
|
|
|
static float |
static float |
cputime(int indx) |
cputime(int indx) |
{ |
{ |
|
|
return (s.time[indx] * 100.0 / t); |
return (s.time[indx] * 100.0 / t); |
} |
} |
|
|
static void |
void |
putint(int n, int l, int c, int w) |
putint(int n, int l, int c, int w) |
{ |
{ |
char b[128]; |
char b[128]; |
|
|
addstr(b); |
addstr(b); |
} |
} |
|
|
static void |
void |
putuint64(u_int64_t n, int l, int c, int w) |
putuint64(u_int64_t n, int l, int c, int w) |
{ |
{ |
char b[128]; |
char b[128]; |
|
|
addstr(b); |
addstr(b); |
} |
} |
|
|
static void |
void |
putfloat(double f, int l, int c, int w, int d, int nz) |
putfloat(double f, int l, int c, int w, int d, int nz) |
{ |
{ |
char b[128]; |
char b[128]; |