zoukankan      html  css  js  c++  java
  • 巧用select延时

    在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
    ");
    	select(0, NULL, NULL, NULL, &time);
    	printf("end
    ");
    	
    	return 0;
    }

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

  • 相关阅读:
    学习进度条64
    学习进度条63
    学习进度条62
    学习进度条61
    学习进度条60
    学习进度条59
    学习进度条58
    学习进度条57
    学习进度条56
    学习进度条55
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/7204014.html
Copyright © 2011-2022 走看看