测试Context Switch time(进程上下文切换时间) 
-------------------------------------------------- 
    创建两个进程(实时进程)并在它们之间传送一个令牌,如此往返传送一定的次数。其中一个进程在读取令牌时就会引起阻塞。另一个进程发送令牌后等待其返回时也处于阻塞状态。发送令牌带来的开销与上下文切换带来的开销相比,可以忽略不计。 (利用管道传递令牌) 

测试程序(1) 使用gettimeofday()获取当前时间

-------------------------------------------------- 

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <sched.h>
#include <sys/types.h>
#include <unistd.h> //pipe() int main()
{
int x, i, fd[2], p[2];
char send = 's';
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, &param);
gettimeofday(&tv, NULL);
printf("Before Context Switch Time %u us\n", tv.tv_usec);
for (i = 0; i < 10000; i++) {
read(fd[0], &receive, 1);
write(p[1], &send, 1);
}
exit(0);
}
else {
sched_setscheduler(getpid(), SCHED_FIFO, &param);
for (i = 0; i < 10000; i++) {
write(fd[1], &send, 1);
read(p[0], &receive, 1);
}
gettimeofday(&tv, NULL);
printf("After Context SWitch Time %u us\n", tv.tv_usec);
}
return 0;
}

最新文章

  1. PyAutoGUI 简介
  2. 真机测试无缘无故finish了。程序也没有启动
  3. Node.js&#160;的初步理解
  4. 将递归函数非递归化的一般方法(cont)
  5. SQL Server TVPs 批量插入数据
  6. 低延时的P2P HLS直播技术实践
  7. LeetCode 78 - 子集
  8. [UE4]Grabbable接口
  9. C语言编程漫谈——main函数
  10. SpringBoot Junit Maven JaCoCo
  11. JQUERY方法给TABLE动态增加行
  12. mongodb int字段的一个小坑
  13. POJ:2386 Lake Counting(dfs)
  14. Mysql 日期类型 date、datetime、timestamp.
  15. Spring3.x错误---- Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
  16. UBUNTU 下 APACHE2 Too many open files: Error retrieving pid file /var/run/apache2.pid
  17. VS2010中生成遇到的 web.config 问题
  18. 在windows中使用Navicat连接Linux虚拟机中的mysql数据库
  19. azkaban平台的使用
  20. php 当不确定用户输入的是浮点 还是整数 还是字符串时

热门文章

  1. 23种设计模式UML表示形式
  2. JavaWeb 文件上传下载
  3. 【转载】关于C++中cin的几点说明性总结
  4. RequestMapping请求映射方式
  5. 4.JDBC编程
  6. mongodb 的主从配置
  7. [转载]Struts2.1.6+Spring2.5.6+Hibernate3.3.
  8. 怎样在WIN7系统下安装IIS和配置ASP
  9. [kuangbin带你飞]专题十 匹配问题 一般图匹配
  10. 比较好的sql写法