/******************************************************************************************************************
参考:1 http://blog.youkuaiyun.com/sunxx1986/article/details/6883909
说明:linux socket的select函数例)。
******************************************************************************************************************/
1.只做定时器
#include <stdio.h>
#include <unistd.h>
#include <sys/select.h>
#include <sys/time.h>
int main()
{
int rc = 0;
struct timeval tv;
tv.tv_sec = 5;
tv.tv_usec = 0;
while(1)
{
tv.tv_sec = 5;
tv.tv_usec = 0;
printf("a\n");
rc = select(0, NULL, NULL, NULL, &tv);
printf("rc = %d\n", rc);
if(rc == 0)
printf("b\n");
else
printf("error !\n");
}
return 0;
}
这样可以省去考虑的东西很多,就最后一个&tv起作用了,其它一概不考虑,这就是一个比sleep精度稍高的定时器。