2006-03-16 02:29:51 +01:00
|
|
|
|
2006-03-17 08:54:55 +01:00
|
|
|
/* Author: Ben Gras <beng@few.vu.nl> 17 march 2006 */
|
|
|
|
|
2006-03-16 02:29:51 +01:00
|
|
|
#define _MINIX 1
|
|
|
|
#define _POSIX_SOURCE 1
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <pwd.h>
|
2006-03-29 01:42:55 +02:00
|
|
|
#include <curses.h>
|
2006-03-16 02:29:51 +01:00
|
|
|
#include <timers.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <termcap.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <signal.h>
|
2006-03-29 01:42:55 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
2006-03-16 02:29:51 +01:00
|
|
|
|
|
|
|
#include <sys/ioc_tty.h>
|
|
|
|
#include <sys/times.h>
|
|
|
|
#include <sys/types.h>
|
2006-03-29 01:42:55 +02:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/select.h>
|
2006-03-16 02:29:51 +01:00
|
|
|
|
|
|
|
#include <minix/ipc.h>
|
2008-12-11 15:27:18 +01:00
|
|
|
#include <minix/com.h>
|
|
|
|
#include <minix/sysinfo.h>
|
2006-03-16 02:29:51 +01:00
|
|
|
#include <minix/config.h>
|
|
|
|
#include <minix/type.h>
|
|
|
|
#include <minix/const.h>
|
|
|
|
|
2010-02-10 16:38:27 +01:00
|
|
|
#include <minix/u64.h>
|
|
|
|
|
2010-03-09 10:41:14 +01:00
|
|
|
#include <machine/archtypes.h>
|
2010-05-12 18:28:54 +02:00
|
|
|
#include "pm/mproc.h"
|
|
|
|
#include "kernel/const.h"
|
|
|
|
#include "kernel/proc.h"
|
2006-03-16 02:29:51 +01:00
|
|
|
|
2008-12-11 15:27:18 +01:00
|
|
|
u32_t system_hz;
|
|
|
|
|
2006-03-16 02:29:51 +01:00
|
|
|
#define TC_BUFFER 1024 /* Size of termcap(3) buffer */
|
|
|
|
#define TC_STRINGS 200 /* Enough room for cm,cl,so,se */
|
|
|
|
|
2006-03-29 01:42:55 +02:00
|
|
|
char *Tclr_all;
|
|
|
|
|
2010-03-03 16:45:43 +01:00
|
|
|
int blockedverbose = 0;
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
2006-03-16 02:29:51 +01:00
|
|
|
int print_memory(struct pm_mem_info *pmi)
|
|
|
|
{
|
|
|
|
int h;
|
|
|
|
int largest_bytes = 0, total_bytes = 0;
|
|
|
|
for(h = 0; h < _NR_HOLES; h++) {
|
|
|
|
if(pmi->pmi_holes[h].h_base && pmi->pmi_holes[h].h_len) {
|
|
|
|
int bytes;
|
|
|
|
bytes = pmi->pmi_holes[h].h_len << CLICK_SHIFT;
|
|
|
|
if(bytes > largest_bytes) largest_bytes = bytes;
|
|
|
|
total_bytes += bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Mem: %dK Free, %dK Contiguous Free\n",
|
|
|
|
total_bytes/1024, largest_bytes/1024);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2008-11-19 13:26:10 +01:00
|
|
|
#endif
|
2006-03-16 02:29:51 +01:00
|
|
|
|
|
|
|
int print_load(double *loads, int nloads)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
printf("load averages: ");
|
|
|
|
for(i = 0; i < nloads; i++)
|
|
|
|
printf("%s %.2f", (i > 0) ? "," : "", loads[i]);
|
|
|
|
printf("\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PROCS (NR_PROCS+NR_TASKS)
|
|
|
|
|
|
|
|
int print_proc_summary(struct proc *proc)
|
|
|
|
{
|
|
|
|
int p, alive, running, sleeping;
|
|
|
|
|
|
|
|
alive = running = sleeping = 0;
|
|
|
|
|
|
|
|
for(p = 0; p < PROCS; p++) {
|
|
|
|
if(p - NR_TASKS == IDLE)
|
|
|
|
continue;
|
2009-11-12 09:35:26 +01:00
|
|
|
if(isemptyp(&proc[p]))
|
2006-03-16 02:29:51 +01:00
|
|
|
continue;
|
|
|
|
alive++;
|
2009-11-12 09:35:26 +01:00
|
|
|
if(!proc_is_runnable(&proc[p]))
|
2006-03-16 02:29:51 +01:00
|
|
|
sleeping++;
|
|
|
|
else
|
|
|
|
running++;
|
|
|
|
}
|
|
|
|
printf("%d processes: %d running, %d sleeping\n",
|
|
|
|
alive, running, sleeping);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct tp {
|
|
|
|
struct proc *p;
|
2010-02-10 16:38:27 +01:00
|
|
|
u64_t ticks;
|
2010-03-03 16:45:43 +01:00
|
|
|
};
|
2006-03-16 02:29:51 +01:00
|
|
|
|
|
|
|
int cmp_ticks(const void *v1, const void *v2)
|
|
|
|
{
|
2010-03-03 16:45:43 +01:00
|
|
|
int c;
|
2006-03-16 02:29:51 +01:00
|
|
|
struct tp *p1 = (struct tp *) v1, *p2 = (struct tp *) v2;
|
2010-03-03 16:45:43 +01:00
|
|
|
int p1blocked, p2blocked;
|
|
|
|
|
|
|
|
p1blocked = !!p1->p->p_rts_flags;
|
|
|
|
p2blocked = !!p2->p->p_rts_flags;
|
|
|
|
|
|
|
|
/* Primarily order by used number of cpu cycles.
|
|
|
|
*
|
|
|
|
* Exception: if in blockedverbose mode, a blocked
|
|
|
|
* process is always printed after an unblocked
|
|
|
|
* process, and used cpu cycles don't matter.
|
|
|
|
*
|
|
|
|
* In both cases, process slot number is a tie breaker.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(blockedverbose && (p1blocked || p2blocked)) {
|
|
|
|
if(!p1blocked && p2blocked)
|
2010-02-10 16:38:27 +01:00
|
|
|
return -1;
|
2010-03-03 16:45:43 +01:00
|
|
|
if( p2blocked && !p1blocked)
|
|
|
|
return 1;
|
|
|
|
} else if((c=cmp64(p1->ticks, p2->ticks)) != 0)
|
|
|
|
return -c;
|
|
|
|
|
|
|
|
/* Process slot number is a tie breaker. */
|
|
|
|
|
2006-03-16 02:29:51 +01:00
|
|
|
if(p1->p->p_nr < p2->p->p_nr)
|
|
|
|
return -1;
|
|
|
|
if(p1->p->p_nr > p2->p->p_nr)
|
|
|
|
return 1;
|
2010-03-03 16:45:43 +01:00
|
|
|
|
|
|
|
fprintf(stderr, "unreachable.\n");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct tp *lookup(endpoint_t who, struct tp *tptab, int np)
|
|
|
|
{
|
|
|
|
int t;
|
|
|
|
|
|
|
|
for(t = 0; t < np; t++)
|
|
|
|
if(who == tptab[t].p->p_endpoint)
|
|
|
|
return &tptab[t];
|
|
|
|
|
|
|
|
fprintf(stderr, "lookup: tp %d (0x%x) not found.\n", who, who);
|
|
|
|
abort();
|
|
|
|
|
|
|
|
return NULL;
|
2006-03-16 02:29:51 +01:00
|
|
|
}
|
|
|
|
|
2010-02-10 16:38:27 +01:00
|
|
|
/*
|
|
|
|
* since we don't have true div64(u64_t, u64_t) we scale the 64 bit counters to
|
|
|
|
* 32. Since the samplig happens every ~1s and the counters count CPU cycles
|
|
|
|
* during this period, unless we have extremely fast CPU, shifting the counters
|
|
|
|
* by 12 make them 32bit counters which we can use for normal integer
|
|
|
|
* arithmetics
|
|
|
|
*/
|
|
|
|
#define SCALE (1 << 12)
|
|
|
|
|
2010-03-03 16:45:43 +01:00
|
|
|
void print_proc(struct tp *tp, struct mproc *mpr, u32_t tcyc)
|
|
|
|
{
|
|
|
|
int euid = 0;
|
|
|
|
static struct passwd *who = NULL;
|
|
|
|
static int last_who = -1;
|
|
|
|
char *name = "";
|
|
|
|
unsigned long pcyc;
|
|
|
|
int ticks;
|
|
|
|
struct proc *pr = tp->p;
|
|
|
|
|
|
|
|
printf("%5d ", mpr->mp_pid);
|
|
|
|
euid = mpr->mp_effuid;
|
|
|
|
name = mpr->mp_name;
|
|
|
|
|
|
|
|
if(last_who != euid || !who) {
|
|
|
|
who = getpwuid(euid);
|
|
|
|
last_who = euid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(who && who->pw_name) printf("%-8s ", who->pw_name);
|
|
|
|
else if(pr->p_nr >= 0) printf("%8d ", mpr->mp_effuid);
|
|
|
|
else printf(" ");
|
|
|
|
|
|
|
|
printf(" %2d ", pr->p_priority);
|
|
|
|
if(pr->p_nr >= 0) {
|
|
|
|
printf(" %3d ", mpr->mp_nice);
|
|
|
|
} else printf(" ");
|
|
|
|
printf("%5dK",
|
|
|
|
((pr->p_memmap[T].mem_len +
|
|
|
|
pr->p_memmap[D].mem_len) << CLICK_SHIFT)/1024);
|
|
|
|
printf("%6s", pr->p_rts_flags ? "" : "RUN");
|
|
|
|
ticks = pr->p_user_time;
|
|
|
|
printf(" %3d:%02d ", (ticks/system_hz/60), (ticks/system_hz)%60);
|
|
|
|
|
|
|
|
pcyc = div64u(tp->ticks, SCALE);
|
|
|
|
|
|
|
|
printf("%6.2f%% %s", 100.0*pcyc/tcyc, name);
|
|
|
|
}
|
|
|
|
|
2006-03-16 02:29:51 +01:00
|
|
|
void print_procs(int maxlines,
|
2010-02-10 16:38:27 +01:00
|
|
|
struct proc *proc1, struct proc *proc2,
|
2006-03-16 02:29:51 +01:00
|
|
|
struct mproc *mproc)
|
|
|
|
{
|
2006-03-17 21:04:55 +01:00
|
|
|
int p, nprocs, tot=0;
|
2010-02-10 16:38:27 +01:00
|
|
|
u64_t idleticks = cvu64(0);
|
|
|
|
u64_t kernelticks = cvu64(0);
|
|
|
|
u64_t systemticks = cvu64(0);
|
|
|
|
u64_t userticks = cvu64(0);
|
|
|
|
u64_t total_ticks = cvu64(0);
|
|
|
|
unsigned long tcyc;
|
|
|
|
unsigned long tmp;
|
2010-03-03 16:45:43 +01:00
|
|
|
int blockedseen = 0;
|
|
|
|
struct tp tick_procs[PROCS];
|
2006-03-29 01:44:10 +02:00
|
|
|
|
2006-03-16 02:29:51 +01:00
|
|
|
for(p = nprocs = 0; p < PROCS; p++) {
|
2009-11-12 09:35:26 +01:00
|
|
|
if(isemptyp(&proc2[p]))
|
2006-03-16 02:29:51 +01:00
|
|
|
continue;
|
|
|
|
tick_procs[nprocs].p = proc2 + p;
|
2006-03-16 02:44:06 +01:00
|
|
|
if(proc1[p].p_endpoint == proc2[p].p_endpoint) {
|
|
|
|
tick_procs[nprocs].ticks =
|
2010-02-10 16:38:27 +01:00
|
|
|
sub64(proc2[p].p_cycles, proc1[p].p_cycles);
|
2006-03-16 02:44:06 +01:00
|
|
|
} else {
|
|
|
|
tick_procs[nprocs].ticks =
|
2010-02-10 16:38:27 +01:00
|
|
|
proc2[p].p_cycles;
|
2006-03-16 02:44:06 +01:00
|
|
|
}
|
2010-02-10 16:38:27 +01:00
|
|
|
total_ticks = add64(total_ticks, tick_procs[nprocs].ticks);
|
2006-03-16 02:29:51 +01:00
|
|
|
if(p-NR_TASKS == IDLE) {
|
|
|
|
idleticks = tick_procs[nprocs].ticks;
|
|
|
|
continue;
|
|
|
|
}
|
2010-02-10 16:38:27 +01:00
|
|
|
if(p-NR_TASKS == KERNEL) {
|
|
|
|
kernelticks = tick_procs[nprocs].ticks;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(mproc[proc2[p].p_nr].mp_procgrp == 0)
|
|
|
|
systemticks = add64(systemticks, tick_procs[nprocs].ticks);
|
|
|
|
else if (p > NR_TASKS)
|
|
|
|
userticks = add64(userticks, tick_procs[nprocs].ticks);
|
2006-03-17 11:04:14 +01:00
|
|
|
|
2006-03-16 02:29:51 +01:00
|
|
|
nprocs++;
|
|
|
|
}
|
|
|
|
|
2010-02-10 16:38:27 +01:00
|
|
|
if (!cmp64u(total_ticks, 0))
|
|
|
|
return;
|
|
|
|
|
2006-03-16 02:29:51 +01:00
|
|
|
qsort(tick_procs, nprocs, sizeof(tick_procs[0]), cmp_ticks);
|
|
|
|
|
2010-02-10 16:38:27 +01:00
|
|
|
tcyc = div64u(total_ticks, SCALE);
|
|
|
|
|
|
|
|
tmp = div64u(userticks, SCALE);
|
|
|
|
printf("CPU states: %6.2f%% user, ", 100.0*(tmp)/tcyc);
|
|
|
|
|
|
|
|
tmp = div64u(systemticks, SCALE);
|
|
|
|
printf("%6.2f%% system, ", 100.0*tmp/tcyc);
|
|
|
|
|
|
|
|
tmp = div64u(kernelticks, SCALE);
|
|
|
|
printf("%6.2f%% kernel, ", 100.0*tmp/tcyc);
|
|
|
|
|
|
|
|
tmp = div64u(idleticks, SCALE);
|
|
|
|
printf("%6.2f%% idle", 100.0*tmp/tcyc);
|
|
|
|
|
2010-03-03 16:45:43 +01:00
|
|
|
#define NEWLINE do { printf("\n"); if(--maxlines <= 0) { return; } } while(0)
|
|
|
|
NEWLINE;
|
|
|
|
NEWLINE;
|
2006-03-16 02:29:51 +01:00
|
|
|
|
2010-03-03 16:45:43 +01:00
|
|
|
printf(" PID USERNAME PRI NICE SIZE STATE TIME CPU COMMAND");
|
|
|
|
NEWLINE;
|
2006-03-16 02:29:51 +01:00
|
|
|
for(p = 0; p < nprocs; p++) {
|
|
|
|
struct proc *pr;
|
2010-03-03 16:45:43 +01:00
|
|
|
int pnr;
|
|
|
|
int level = 0;
|
2006-03-16 02:29:51 +01:00
|
|
|
|
|
|
|
pnr = tick_procs[p].p->p_nr;
|
2010-03-03 16:45:43 +01:00
|
|
|
|
|
|
|
if(pnr < 0) {
|
2010-02-10 16:38:27 +01:00
|
|
|
/* skip old kernel tasks as they don't run anymore */
|
|
|
|
continue;
|
2006-03-29 14:44:06 +02:00
|
|
|
}
|
2006-03-16 02:29:51 +01:00
|
|
|
|
2010-03-03 16:45:43 +01:00
|
|
|
pr = tick_procs[p].p;
|
|
|
|
|
|
|
|
/* If we're in blocked verbose mode, indicate start of
|
|
|
|
* blocked processes.
|
|
|
|
*/
|
|
|
|
if(blockedverbose && pr->p_rts_flags && !blockedseen) {
|
|
|
|
NEWLINE;
|
|
|
|
printf("Blocked processes:");
|
|
|
|
NEWLINE;
|
|
|
|
blockedseen = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
print_proc(&tick_procs[p], &mproc[pnr], tcyc);
|
|
|
|
NEWLINE;
|
|
|
|
|
|
|
|
if(!blockedverbose)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Traverse dependency chain if blocked. */
|
|
|
|
while(pr->p_rts_flags) {
|
|
|
|
endpoint_t dep = NONE;
|
|
|
|
struct tp *tpdep;
|
|
|
|
level += 5;
|
2006-03-16 02:29:51 +01:00
|
|
|
|
2010-03-03 16:45:43 +01:00
|
|
|
if((dep = P_BLOCKEDON(pr)) == NONE) {
|
|
|
|
printf("not blocked on a process");
|
|
|
|
NEWLINE;
|
|
|
|
break;
|
|
|
|
}
|
2006-03-16 02:29:51 +01:00
|
|
|
|
2010-03-03 16:45:43 +01:00
|
|
|
if(dep == ANY)
|
|
|
|
break;
|
2010-02-10 16:38:27 +01:00
|
|
|
|
2010-03-03 16:45:43 +01:00
|
|
|
tpdep = lookup(dep, tick_procs, nprocs);
|
|
|
|
pr = tpdep->p;
|
|
|
|
printf("%*s> ", level, "");
|
|
|
|
print_proc(tpdep, &mproc[pr->p_nr], tcyc);
|
|
|
|
NEWLINE;
|
|
|
|
}
|
2006-03-16 02:29:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-22 16:32:44 +01:00
|
|
|
void showtop(int r)
|
2006-03-16 02:29:51 +01:00
|
|
|
{
|
|
|
|
#define NLOADS 3
|
|
|
|
double loads[NLOADS];
|
|
|
|
int nloads, i, p, lines = 0;
|
|
|
|
static struct proc prev_proc[PROCS], proc[PROCS];
|
2010-02-10 16:38:27 +01:00
|
|
|
static int preheated = 0;
|
2006-03-16 02:29:51 +01:00
|
|
|
struct winsize winsize;
|
2008-11-19 13:26:10 +01:00
|
|
|
/*
|
|
|
|
static struct pm_mem_info pmi;
|
|
|
|
*/
|
2006-03-16 02:29:51 +01:00
|
|
|
static struct mproc mproc[NR_PROCS];
|
2008-11-19 13:26:10 +01:00
|
|
|
int mem = 0;
|
2006-03-16 02:29:51 +01:00
|
|
|
|
|
|
|
if(ioctl(STDIN_FILENO, TIOCGWINSZ, &winsize) != 0) {
|
|
|
|
perror("TIOCGWINSZ");
|
|
|
|
fprintf(stderr, "TIOCGWINSZ failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
2006-03-16 02:29:51 +01:00
|
|
|
if(getsysinfo(PM_PROC_NR, SI_MEM_ALLOC, &pmi) < 0) {
|
|
|
|
fprintf(stderr, "getsysinfo() for SI_MEM_ALLOC failed.\n");
|
2008-11-19 13:26:10 +01:00
|
|
|
mem = 0;
|
2006-03-16 02:29:51 +01:00
|
|
|
exit(1);;
|
2008-11-19 13:26:10 +01:00
|
|
|
} else mem = 1;
|
|
|
|
#endif
|
2006-03-16 02:29:51 +01:00
|
|
|
|
2010-02-10 16:38:27 +01:00
|
|
|
retry:
|
2006-03-16 02:29:51 +01:00
|
|
|
if(getsysinfo(PM_PROC_NR, SI_KPROC_TAB, proc) < 0) {
|
|
|
|
fprintf(stderr, "getsysinfo() for SI_KPROC_TAB failed.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-02-10 16:38:27 +01:00
|
|
|
if (!preheated) {
|
|
|
|
preheated = 1;
|
|
|
|
memcpy(prev_proc, proc, sizeof(prev_proc));
|
|
|
|
goto retry;;
|
|
|
|
}
|
2006-03-16 02:29:51 +01:00
|
|
|
|
|
|
|
if(getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc) < 0) {
|
|
|
|
fprintf(stderr, "getsysinfo() for SI_PROC_TAB failed.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if((nloads = getloadavg(loads, NLOADS)) != NLOADS) {
|
|
|
|
fprintf(stderr, "getloadavg() failed - %d loads\n", nloads);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
printf("%s", Tclr_all);
|
|
|
|
|
|
|
|
lines += print_load(loads, NLOADS);
|
|
|
|
lines += print_proc_summary(proc);
|
2008-11-19 13:26:10 +01:00
|
|
|
#if 0
|
|
|
|
if(mem) { lines += print_memory(&pmi); }
|
|
|
|
#endif
|
2006-03-16 02:29:51 +01:00
|
|
|
|
2006-03-22 16:32:44 +01:00
|
|
|
if(winsize.ws_row > 0) r = winsize.ws_row;
|
|
|
|
|
|
|
|
print_procs(r - lines - 2, prev_proc,
|
2010-02-10 16:38:27 +01:00
|
|
|
proc, mproc);
|
2006-03-16 02:29:51 +01:00
|
|
|
|
|
|
|
memcpy(prev_proc, proc, sizeof(prev_proc));
|
|
|
|
}
|
|
|
|
|
2006-03-22 16:32:44 +01:00
|
|
|
void init(int *rows)
|
2006-03-16 02:29:51 +01:00
|
|
|
{
|
|
|
|
char *term;
|
|
|
|
static char buffer[TC_BUFFER], strings[TC_STRINGS];
|
2006-03-22 16:32:44 +01:00
|
|
|
char *s = strings, *v;
|
|
|
|
|
|
|
|
*rows = 0;
|
2006-03-16 02:29:51 +01:00
|
|
|
|
|
|
|
if(!(term = getenv("TERM"))) {
|
|
|
|
fprintf(stderr, "No TERM set\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( tgetent( buffer, term ) != 1 ) {
|
|
|
|
fprintf(stderr, "tgetent failed for term %s\n", term);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (Tclr_all = tgetstr( "cl", &s )) == NULL )
|
|
|
|
Tclr_all = "\f";
|
2006-03-22 16:32:44 +01:00
|
|
|
|
|
|
|
if((v = tgetstr ("li", &s)) != NULL)
|
|
|
|
sscanf(v, "%d", rows);
|
|
|
|
if(*rows < 1) *rows = 24;
|
2006-03-29 01:42:55 +02:00
|
|
|
if(!initscr()) {
|
|
|
|
fprintf(stderr, "initscr() failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
cbreak();
|
|
|
|
nl();
|
2006-03-16 02:29:51 +01:00
|
|
|
}
|
|
|
|
|
2006-03-29 01:42:55 +02:00
|
|
|
void sigwinch(int sig) { }
|
|
|
|
|
2006-03-16 02:29:51 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2006-03-29 01:42:55 +02:00
|
|
|
int r, c, s = 0, orig;
|
|
|
|
|
2008-12-11 15:27:18 +01:00
|
|
|
getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, sizeof(system_hz), &system_hz);
|
|
|
|
|
2006-03-22 16:32:44 +01:00
|
|
|
init(&r);
|
2006-03-16 02:29:51 +01:00
|
|
|
|
2010-03-03 16:45:43 +01:00
|
|
|
while((c=getopt(argc, argv, "s:B")) != EOF) {
|
2006-03-29 01:42:55 +02:00
|
|
|
switch(c) {
|
|
|
|
case 's':
|
|
|
|
s = atoi(optarg);
|
|
|
|
break;
|
2010-03-03 16:45:43 +01:00
|
|
|
case 'B':
|
|
|
|
blockedverbose = 1;
|
|
|
|
break;
|
2006-03-29 01:42:55 +02:00
|
|
|
default:
|
|
|
|
fprintf(stderr,
|
2010-03-03 16:45:43 +01:00
|
|
|
"Usage: %s [-s<secdelay>] [-B]\n",
|
|
|
|
argv[0]);
|
2006-03-29 01:42:55 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(s < 1)
|
|
|
|
s = 2;
|
|
|
|
|
2010-03-03 16:45:43 +01:00
|
|
|
/* Catch window size changes so display is updated properly
|
|
|
|
* right away.
|
|
|
|
*/
|
2006-03-29 01:42:55 +02:00
|
|
|
signal(SIGWINCH, sigwinch);
|
|
|
|
|
2006-03-16 02:29:51 +01:00
|
|
|
while(1) {
|
2006-03-29 01:42:55 +02:00
|
|
|
fd_set fds;
|
|
|
|
int ns;
|
|
|
|
struct timeval tv;
|
2006-03-22 16:32:44 +01:00
|
|
|
showtop(r);
|
2006-03-29 01:42:55 +02:00
|
|
|
tv.tv_sec = s;
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
|
|
|
|
FD_ZERO(&fds);
|
|
|
|
FD_SET(STDIN_FILENO, &fds);
|
|
|
|
if((ns=select(STDIN_FILENO+1, &fds, NULL, NULL, &tv)) < 0
|
|
|
|
&& errno != EINTR) {
|
|
|
|
perror("select");
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ns > 0 && FD_ISSET(STDIN_FILENO, &fds)) {
|
|
|
|
char c;
|
|
|
|
if(read(STDIN_FILENO, &c, 1) == 1) {
|
|
|
|
switch(c) {
|
|
|
|
case 'q':
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-03-16 02:29:51 +01:00
|
|
|
}
|
2006-03-29 01:42:55 +02:00
|
|
|
|
|
|
|
return 0;
|
2006-03-16 02:29:51 +01:00
|
|
|
}
|
|
|
|
|