在LINUX用户态的情况下。假设想要延时的话。用sleep是最合适的,可是,在有些情况下,须要更小单位的延时,ms  us 也是要的。用循环获取到的延时是不精确的。

幸好,select函数巧用的话,是能够做到延时的效果的。

废话不多说,直接上code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main(int argc, char *argv[])
{
	unsigned long long a;
	struct timeval time;
	
	time.tv_sec = 5;
	time.tv_usec = 0;

	printf("start , sleep 5 sec\n");
	select(0, NULL, NULL, NULL, &time);
	printf("end\n");
	
	return 0;
}

设置下相应的 time的值即哥完毕延时。

相关文章:

  • 2021-12-05
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-14
  • 2021-12-19
  • 2021-12-03
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
相关资源
相似解决方案