📄 test.c
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -