test.c

来自「MINIX操作系统的内核修改补丁」· C语言 代码 · 共 55 行

C
55
字号
#include <stdio.h>
#include <stdlib.h>

#include <unistd.h>
#include <sys/types.h>
#include <time.h>
#include <sys/resource.h>

extern int setdl (long); /* system call */

int delay(void)
{
  int i, sum;
  for (i = 0; i < 1000; i++)
      sum += rand();
  return sum;
}

void testrt (void)
{
  time_t recent, new;  /* times */
  int count, inner;

  setdl (120); /* let all other RT processes start up */
  sleep (1);   /* while we sleep */
  recent = time (NULL);
  count = 0;
  while (count < 100) {
    while ((new = time (NULL)) == recent) { /* still on the same second */
      setdl(60);               /* check time again within one second */
      delay();
    }
    if (new == (recent + 1)) {  /* new second: did we skip any? */
      count++;                  /* no -- still working in realtime */
    } else {                    /* missed the deadline */
      setdl(0);                /* no longer real time */
      printf ("missed deadline after %d seconds\n", count);
      return;
    }
    recent = new;
  }
  setdl(0);                    /* no longer real time */
  printf ("successfully met %d successive deadlines\n", count);
}

int main (int argc, char ** argv)
{
	fork();
	fork();
	fork();
	fork();
  testrt ();
  return 0;
}

⌨️ 快捷键说明

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