免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1157 | 回复: 2
打印 上一主题 下一主题

[函数] select函数出错,大家看看怎么回事?急问阿 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-06-03 16:02 |只看该作者 |倒序浏览
环境: HP-UX 11 c语言编程
目的是使用select做定时器

源代码如下:


  1. #include <stdio.h>;
  2. #include <stdlib.h>;
  3. #include <sys/time.h>;
  4. #include <sys/types.h>;
  5. #include <unistd.h>;

  6. int
  7. main(void)
  8. {

  9. int ret;
  10. struct timeval delay;
  11. time_t t1,t2;

  12. delay.tv_sec =0 ;
  13. delay.tv_usec = 1000000;
  14. time(&t1);
  15. ret = select(0,NULL,NULL,NULL,&delay);
  16. time(&t2);

  17. if (ret == -1)
  18. {
  19. printf("select error!!\n");
  20. return -1;
  21. }
  22. printf("end-start time is %d\n",t2-t1);
  23. return 0;

  24. }

复制代码

编译 cc -g select.c
执行 ./a.out

结果输出select error!!

但是在linux7.2下就能输出1,
请大家帮忙看看是怎么回事?多谢了

论坛徽章:
0
2 [报告]
发表于 2003-06-03 16:12 |只看该作者

select函数出错,大家看看怎么回事?急问阿

errno是什么?
delay.tv_usec = 1000000L;试试。

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
3 [报告]
发表于 2003-06-03 18:48 |只看该作者

select函数出错,大家看看怎么回事?急问阿

http://www.chinaunix.net/forum/viewtopic.php?t=78785
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP