/* http://www.cyut.edu.tw/~ckhung/b/mi/ */ /* 1999-06 */ /* usage: sysinfo [row [col]] */ /* Note: the screen must support ANSI escape sequences */ /* (Best left running in the background.) */ #include #include #include #include #include #include #include int main(int argc, char *argv[]) { const char ESC = '\x1b'; int r, c, np, i; time_t x; struct tm * now; DIR * proc; struct dirent * de; r = argc > 1 ? atoi(argv[1]) : 1; c = argc > 2 ? atoi(argv[2]) : 72; while (1) { time(& x); now = localtime(& x); proc = opendir("/proc"); np = 0; while ((de = readdir(proc)) != NULL) { for (i=0; de->d_name[i]; ++i) if (! isdigit(de->d_name[i])) break; if (de->d_name[i] == '\0') ++np; } closedir(proc); printf("%c7%c[7m", ESC, ESC); printf("%c[%d;%dH%02d:%02d:%02d%c[K", ESC, r, c, now->tm_hour, now->tm_min, now->tm_sec, ESC); printf("%c[%d;%dH%4d%c[K", ESC, r+1, c, np, ESC); printf("%c[m%c8", ESC, ESC); fflush(stdout); sleep(1); } return 0; }