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

📄 mosmon.c

📁 OpenMosix工具
💻 C
📖 第 1 页 / 共 3 页
字号:
  exit (errmsg ? 1 : 0);}				/* usage *//*********************************************************************** *_____________________________  SET_MODE _____________________________* ***********************************************************************//*** set item and clear old mode (reuse argument as counter)*/voidset_mode (int i){  item = i;  for (i = 1; i <= npe; i++)    load[i] = MAX_SILENT - 1;}				/* set_mode *//********************************************************************** *_____________________________  GET_NPE _____________________________* **********************************************************************//*** PROC_HPC_INFOS is a special proc file.** On this file, lseek() jumps across records instead of bytes.**** Note that on "normal" files lseek() jumps across bytes,** on proc files it usually does not work (EINVAL).**** By jumping directly to end of file, we get the total number of** records stored inside the file. No more needs for find_npe().**** npe may be 0 when oM unconfigured (empty file)*/voidget_npe (void){  npe = (int) lseek (ifd, 0L, SEEK_END);	// goto EOF  (void) lseek (ifd, 0L, SEEK_SET);	// goto SOF  if (npe == -1)    npe = 0;  DBGprint ("npe = %d", npe);  if (!npe)			// give us a second chance, just in case...    {      find_npe ();      DBGprint ("npe = %d", npe);    }}				/* get_npe *//*********************************************************************** *_____________________________  FIND_NPE _____________________________* ***********************************************************************//* superseded by get_npe() *//*** Computes the number of records on /proc/hpc/info/infos.** Note that this is a PROC_HPC_INFOS specific implementation, on normal** file lseek() jumps across bytes, not records...*/voidfind_npe (void){  register int i;  void *dummy = xcmalloc (recsz);	// oM version specific, size may change  int onpe = npe;  for (npe = i = 1; npe <= MOSIX_MAX; i = npe, npe += npe)    {      lseek (ifd, npe - 1, SEEK_SET);      if (read (ifd, dummy, recsz) != recsz)	break;    }  while (npe > i + 1)    {      lseek (ifd, (i + npe) / 2 - 1, SEEK_SET);      if (read (ifd, dummy, recsz) != recsz)	npe = (i + npe) / 2;      else	i = (i + npe) / 2;    }  npe = i;  for (i = onpe + 1; i <= npe; i++)    load[i] = valid[i] = 0;  free (dummy);  DBGprint ("npe = %d", npe);  adjust_first ();}				/* find_npe */#if 0				//{/*** old/original version of find_npe(), adapted above, superseded by get_npe()*/voidfind_npe (){  register int i;  struct mosix_info x;  int onpe = npe;  for (npe = i = 1; npe <= MOSIX_MAX; i = npe, npe += npe)    {      lseek (ifd, npe - 1, 0);      if (read (ifd, &x, RECSZ) != RECSZ)	break;    }  while (npe > i + 1)    {      lseek (ifd, (i + npe) / 2 - 1, 0);      if (read (ifd, &x, RECSZ) != RECSZ)	npe = (i + npe) / 2;      else	i = (i + npe) / 2;    }  npe = i;  for (i = onpe + 1; i <= npe; i++)    load[i] = valid[i] = 0;  adjust_first ();}#endif //}/*************************************************************************** *_____________________________  ADJUST_FIRST _____________________________* ***************************************************************************//*** which is the first node to display ?*/voidadjust_first (void){  if (first >= npe)    first = npe;  if (first < 1)    first = 1;}				/* adjust_first *//* my_getch() - input stuff: */char esc_no_wait;int un_char, las_char;/*********************************************************************** *_____________________________  CH_ALARM _____________________________* ***********************************************************************/voidch_alarm (void){  signal (SIGALRM, (sig_t) ch_alarm);}				/* ch_alarm *//************************************************************************* *_____________________________  NOT_YET_CH _____________________________* *************************************************************************/voidnot_yet_ch (int ch){  if (ch)    un_char = ch;  else if (las_char && las_char != ERR)    un_char = las_char;}				/* not_yet_ch *//******************************************************************************** *_____________________________  READC_HALF_SECOND _____________________________* ********************************************************************************/intreadc_half_second (void){  char r = ERR;  int a;  struct itimerval t, tt;  if (ioctl (STDIN_FILENO, FIONREAD, &a) >= 0 && a > 0)    read (STDIN_FILENO, &r, 1);  else if (esc_no_wait)    return (ERR);  else    {      signal (SIGALRM, (sig_t) ch_alarm);      t.it_interval.tv_sec = 0;      t.it_interval.tv_usec = 500000;      t.it_value = t.it_interval;      setitimer (ITIMER_REAL, &t, &tt);      read (STDIN_FILENO, &r, 1);      t.it_interval.tv_usec = t.it_interval.tv_sec = 0;      t.it_value = t.it_interval;      setitimer (ITIMER_REAL, &t, &tt);    }  return (r);}				/* readc_half_second *//*********************************************************************** *_____________________________  MY_GETCH _____________________________* ***********************************************************************/intmy_getch (void){  char r = ERR;  if (un_char && un_char != ERR)    {      las_char = un_char;      un_char = 0;      return (las_char);    }  read (STDIN_FILENO, &r, 1);  if (r == '\33')    {      r = readc_half_second ();      if (r == ERR)	return (las_char = '\33');      if (r == '[' || r == 'O')	{	  /*	   ** special keys ESC[X, ESC[X~	   */	  switch (r = readc_half_second ())	    {	    case 'A':	      return (las_char = KEY_UP);	    case 'B':	      return (las_char = KEY_DOWN);	    case 'C':	      return (las_char = KEY_RIGHT);	    case 'D':	      return (las_char = KEY_LEFT);	    case 'M':	      return (las_char = KEY_ENTER);	    case 'q':	    case 'F':	      return (las_char = KEY_C1);	    case 'r':	      return (las_char = KEY_DOWN);	    case 's':	    case 'G':	      return (las_char = KEY_C3);	    case 't':	      return (las_char = KEY_LEFT);	    case 'v':	      return (las_char = KEY_RIGHT);	    case 'w':	    case 'x':	      return (las_char = KEY_UP);	    case 'y':	    case 'I':	      return (las_char = KEY_A3);	    case 'H':	      return (las_char = KEY_HOME);//              return( las_char = KEY_A1 );	    case '1':	      if (readc_half_second () == '~')		return (las_char = KEY_HOME);	      break;	    case '2':	      if (readc_half_second () == '~')		return (las_char = KEY_IC);	// INSERT = ESC[2~	      break;	    case '5':	    case '6':	      if (readc_half_second () == '~')		return (las_char = (r == '5' ? KEY_A3 : KEY_C3));	      break;	    default:	      break;	    }	  return (las_char = r);	}      else	return (las_char = r);    }  else    return (las_char = r);}				/* my_getch *//********************************************************************** *_____________________________  ISINPUT _____________________________* **********************************************************************/intis_input (void){  int r;  return ((un_char && un_char != ERR) ||	  (ioctl (STDIN_FILENO, FIONREAD, &r) >= 0 && r > 0));}				/* is_input *//******************************************************************* *_____________________________  HELP _____________________________* *******************************************************************/voidhelp (void){  static WINDOW *w1, *w2;  int c;  w1 = newwin (0, 0, 0, 0);  if (w1 == NULL)    printf ("error creating help.exiting..\n"), onint (1);  waddstr (w1, HELP_STR1);  waddstr (w1, "\nPress ESC to exit help or any other key to continue...");  w2 = newwin (0, 0, 0, 0);  if (w2 == NULL)    printf ("error creating help.exiting..\n"), onint (1);  waddstr (w2, HELP_STR2);  waddstr (w2, "\nPress any key to continue...");  /* run */  alarm (0);  clearok (w1, TRUE);  wrefresh (w1);  refresh ();  c = wgetch (w1);  if (c == 'q' || c == 'Q')    onint (0);#define ESC '\033'  if (c != ESC)    {      clearok (w2, TRUE);      wrefresh (w2);      refresh ();      c = wgetch (w2);      if (c == 'q' || c == 'Q')	onint (0);    }#undef ESC  delwin (w1);  delwin (w2);  clearok (stdscr, TRUE);  refresh ();}				/* help *//************************************************************************ *_____________________________  YARDSTICK _____________________________* ************************************************************************/voidyardstick (void){  static WINDOW *w;  char buf[1025];  FILE *yard = fopen (PROC_HPC_SSPEED, "r");  int n;  if (!yard || fscanf (yard, "%d", &n) != 1)    sprintf (buf, "Sorry, Failed obtaining yardstick: [%d] %m\n", errno);  else    sprintf (buf, "Yardstick speed currently set to %d\n", n);  if (yard)    fclose (yard);  w = newwin (0, 0, 0, 0);  if (w == NULL)    printf ("error creating yardwindow.exiting..\n"), onint (1);  waddstr (w, buf);  waddstr (w, "\nPress Any Key to Continue...");  /* run */  alarm (0);  clearok (w, TRUE);  wrefresh (w);  wgetch (w);  delwin (w);  clearok (stdscr, TRUE);  refresh ();}				/* yardstick *//***************************************************************** *_____________________________  CB _____________________________* *****************************************************************/voidcb (const char *msg, int y, int x){  static int mode = 0;  static WINDOW *wn;  if (mode == 0)		/* create */    {      wn = newwin (LINES / 3, COLS * 4 / 9, LINES / 3, COLS / 3);      if (wn == NULL)	printf ("very bad\n"), onint (1);      mode = 1;    }  else    wclear (wn);  alarm (0);  clearok (wn, TRUE);  box (wn, '|', '-');  wmove (wn, y, x);  waddstr (wn, msg);  wrefresh (wn);  sleep (1);  clearok (stdscr, TRUE);  refresh ();}				/* cb *//********************************************************************* *_____________________________  CB_CTR _____________________________* *********************************************************************//*** same of cb() but autocentered (min screen size 43x9 :)*/voidcb_ctr (const char *msg){  static int mode = 0;  static WINDOW *wn;  int nlines = (LINES / 3);  int ncols = (COLS * 4 / 9);  int begin_y = (LINES / 3);  int begin_x = (COLS / 3);  if (mode == 0)		/* create */    {      wn = newwin (nlines, ncols, begin_y, begin_x);      if (wn == NULL)	printf ("very bad\n"), onint (1);      mode = 1;    }  else    wclear (wn);  alarm (0);  clearok (wn, TRUE);  box (wn, '|', '-');  wmove (wn, (nlines / 2), (ncols / 2) - (strlen (msg) / 2));  waddstr (wn, msg);  wrefresh (wn);  sleep (1);  clearok (stdscr, TRUE);  refresh ();}				/* cb_ctr *//******************************************************************* *_____________________________  ONIO _____________________________* *******************************************************************/struct sigaction act;voidonio (void){  act.sa_handler = (sig_t) onio;  sigaction (SIGALRM, &act, 0);  alarm (1);}				/* onio *//***************************************************************************** *_____________________________  SLEEP_OR_INPUT _____________________________* *****************************************************************************/voidsleep_or_input (unsigned int secs){  if (is_input ())    return;  act.sa_handler = (sig_t) onio;  sigaction (SIGALRM, &act, 0);  alarm (secs);  if (my_getch () != ERR)    not_yet_ch (0);  alarm (0);}				/* sleep_or_input *//******************************************************************** *_____________________________  ONINT _____________________________* ********************************************************************//*** clear window before exit*/voidonint (int i){  clear ();  echo ();  nocbreak ();  system ("stty -cbreak echo");  move (LINES - 1, 0);  refresh ();  endwin ();  ioctl (STDIN_FILENO, TCIOFLUSH, 0);  exit (i);}				/* onint *//***********************  E N D   O F   F I L E  ************************/

⌨️ 快捷键说明

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