- 论坛徽章:
- 0
|
今天写了一个测试程序,本想测试PREEMPT RT LINUX的时间精度,可程序总是阻塞在第30行。
第29行的printf("\nMSG:1.The second is:%d ,the nanosecond is :%d", t.tv_sec, t.tv_nsec);可以输出,
但到第31行的printf("\nMSG:2 就没有输出了,光标一直在那里闪动。
按道理来说,程序不应该在第30行或31行那里阻塞啊!!
请教高手!谢谢!
1#include <stdlib.h>
2#include <stdio.h>
3#include <time.h>
4#include <sched.h>
5#include <sys/mman.h>
6#include <string.h>
7#define MY_PRIORITY (49) /* we use 49 as the PRREMPT_RT use 50
8 as the priority of kernel tasklets
9 and interrupt handler by default */
10
11 int main(int argc, char* argv[])
12 {
13 struct timespec t;
14 struct sched_param param;
15 int interval = 10; /* 50us*/
16 /* Declare ourself as a real time task */
17 param.sched_priority = MY_PRIORITY;
18 if(sched_setscheduler(getpid() , SCHED_FIFO, ¶m) == -1) {
19 perror("sched_setscheduler failed");
20 exit(-1);
21 }
22 /* Lock memory */
23 if(mlockall(MCL_CURRENT|MCL_FUTURE) == -1) {
24 perror("mlockall failed");25
26 exit(-2);
27 }
28 clock_gettime(CLOCK_MONOTONIC ,&t);
29 printf("\nMSG:1.The second is:%d ,the nanosecond is :%d", t.tv_sec, t.tv_nsec);
30 clock_gettime(CLOCK_MONOTONIC ,&t);
31 printf("\nMSG:2.The second is:%d ,the nanosecond is :%d", t.tv_sec, t.tv_nsec);
32 clock_nanosleep(2, TIMER_ABSTIME, &t, NULL);
33 clock_gettime(CLOCK_MONOTONIC ,&t);
34 printf("\nMSG:3.The second is:%d ,the nanosecond is :%d,it is after nanosleep\n", t.tv_sec, t.tv_nsec);
35
36 return 0;
37} |
|