⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csm.c

📁 opensolaris下列出top进程
💻 C
字号:
#include "gui.h"#define INTERVALL 250000intmain (int argc, char **argv){  int slowdown, i;  init_csm ();  init_gui ();  database *data = init_database ();  /* mainloop */  slowdown = 0;  for (;;)    {      usleep (INTERVALL);      calc_cpu (data);      calc_net (data);      calc_mem (data);      calc_disk (data);      if (slowdown % 4 == 0)        calc_top_processes (data);      unsigned int ncolumns, wcolumn;      wcolumn = 20;      ncolumns = (unsigned int) (COLS / 20);      unsigned int vfree[ncolumns];      for (i = 0; i < ncolumns; i++)        {          vfree[i] = LINES;        }      /* output       * first 5 lines show cpu-usage       */      draw_cpu (data, create_dim (0, 0, 5, COLS));      for (i = 0; i < ncolumns; i++)        {          vfree[i] -= 5;        }      // set column and vfree      // return 0 if output wouldn't fit on screen      int position (unsigned int *vfree, int *current_column, int height)      {        if (*current_column > ncolumns)          {            *current_column = 0;          }        if (height > LINES - 5)          {            return 0;          }                     // no chance to bring this to the screen        if (vfree[*current_column] < height)          {            *current_column += 1;            position (vfree, current_column, height);          }        else          {            vfree[*current_column] -= height;            return 1;          }        // XXX: should never reach this        return 0;      }      // TODO: make this more dynamic.      int current_column;      current_column = 0;      if (position (vfree, &current_column, 9))        draw_mem (data,                  create_dim (current_column * wcolumn,                              LINES - vfree[current_column] - 9, 12, 20),                  MBYTES);      if (position (vfree, &current_column, 8))        draw_net (data,                  create_dim (current_column * wcolumn,                              LINES - vfree[current_column] - 8, 8, 20),                  MBYTES);      if (position (vfree, &current_column, 19))        draw_disk (data,                   create_dim (current_column * wcolumn,                               LINES - vfree[current_column] - 19, 19, 20),                   MBYTES);      if (position (vfree, &current_column, NUMBER_PROCESSES))        draw_top_processes (data,                            create_dim (current_column * wcolumn,                                        LINES - vfree[current_column] -                                        NUMBER_PROCESSES, NUMBER_PROCESSES,                                        20));      char input;      input = getch ();      // keypress 'q' means quit      if (input == 'q')        break;      // ":" opens a command line      if (input == ':')        {          char str[5];          echo ();          nodelay (stdscr, FALSE);          mvaddstr (LINES - 2, 0, ":");          getnstr (str, 4);          // TODO: add more commands          if (!strcmp (str, "quit"))            break;          noecho ();          nodelay (stdscr, TRUE);          // clear command line          // XXX: there must be a better way!          mvaddstr (LINES - 2, 0,                    "                                            ");        }      if (slowdown > 10000)        {          slowdown = 0;        }      else        {          slowdown++;        }    }  free_database (data);  quit_gui ();  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -