-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmain.c
executable file
·43 lines (40 loc) · 1.01 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <sched.h>
#include <sys/types.h>
#include <unistd.h>
#define EXEC_COUNT 10000
int main()
{
int x, i, fd[2], p[2];
char send = 'hello';
char receive;
pipe(fd);
pipe(p);
struct timeval tv;
struct sched_param param;
param.sched_priority = 0;
while ((x = fork()) == -1);
if (x==0) {
sched_setscheduler(getpid(), SCHED_FIFO, ¶m);
gettimeofday(&tv, NULL);
printf("开始测试时间:%u s, %u us\n", tv.tv_sec, tv.tv_usec);
for (i = 0; i < EXEC_COUNT; i++) {
read(fd[0], &receive, 1);
write(p[1], &send, 1);
}
exit(0);
}
else {
sched_setscheduler(getpid(), SCHED_FIFO, ¶m);
for (i = 0; i < EXEC_COUNT; i++) {
write(fd[1], &send, 1);
read(p[0], &receive, 1);
}
gettimeofday(&tv, NULL);
printf("结束测试时间:%u s, %u us\n", tv.tv_sec, tv.tv_usec);
}
return 0;
}