296 |
|
} |
297 |
|
|
298 |
|
/* VM */ |
299 |
< |
if (stats.mem_stats != NULL) { |
299 |
> |
if (stats.mem_stats != NULL && stats.mem_stats->total != 0) { |
300 |
|
move(6, 54); |
301 |
|
printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used)/stats.mem_stats->total)); |
302 |
|
} |
303 |
< |
if (stats.swap_stats != NULL) { |
303 |
> |
if (stats.swap_stats != NULL && stats.swap_stats->total != 0) { |
304 |
|
move(7, 54); |
305 |
|
printw("%5.2f%%", (100.00 * (float)(stats.swap_stats->used)/stats.swap_stats->total)); |
306 |
|
} |
307 |
< |
if (stats.mem_stats != NULL && stats.swap_stats != NULL) { |
307 |
> |
if (stats.mem_stats != NULL && stats.swap_stats != NULL && |
308 |
> |
stats.mem_stats->total != 0 && stats.swap_stats->total != 0) { |
309 |
|
move(8, 54); |
310 |
|
printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used+stats.swap_stats->used)/(stats.mem_stats->total+stats.swap_stats->total))); |
311 |
|
} |
430 |
|
|
431 |
|
WINDOW *window; |
432 |
|
|
432 |
– |
int stdin_fileno; |
433 |
– |
fd_set infds; |
434 |
– |
struct timeval timeout; |
435 |
– |
|
433 |
|
extern int errno; |
437 |
– |
char ch; |
434 |
|
|
435 |
|
int delay=2; |
436 |
|
#ifdef ALLBSD |
444 |
|
} |
445 |
|
#endif |
446 |
|
|
447 |
< |
while ((c = getopt(argc, argv, "vhd:")) != EOF){ |
447 |
> |
while ((c = getopt(argc, argv, "vhd:")) != -1){ |
448 |
|
switch (c){ |
449 |
|
case 'd': |
450 |
|
delay = atoi(optarg); |
471 |
|
nonl(); |
472 |
|
cbreak(); |
473 |
|
noecho(); |
474 |
+ |
timeout(delay * 1000); |
475 |
|
window=newwin(0, 0, 0, 0); |
476 |
|
clear(); |
477 |
|
|
482 |
|
} |
483 |
|
|
484 |
|
display_headings(); |
488 |
– |
stdin_fileno=fileno(stdin); |
485 |
|
|
486 |
|
for(;;){ |
487 |
< |
|
488 |
< |
FD_ZERO(&infds); |
489 |
< |
FD_SET(stdin_fileno, &infds); |
490 |
< |
timeout.tv_sec = delay; |
495 |
< |
timeout.tv_usec = 0; |
496 |
< |
|
497 |
< |
if((select((stdin_fileno+1), &infds, NULL, NULL, &timeout)) == -1){ |
498 |
< |
if(errno!=EINTR){ |
499 |
< |
perror("select failed"); |
500 |
< |
exit(1); |
501 |
< |
} |
502 |
< |
} |
503 |
< |
|
504 |
< |
if(FD_ISSET(stdin_fileno, &infds)){ |
505 |
< |
ch=getch(); |
506 |
< |
if (ch == 'q'){ |
507 |
< |
endwin(); |
508 |
< |
return 0; |
509 |
< |
} |
487 |
> |
int ch = getch(); |
488 |
> |
if (ch == 'q'){ |
489 |
> |
endwin(); |
490 |
> |
return 0; |
491 |
|
} |
492 |
|
|
493 |
|
get_stats(); |