linux延时函数
来源:互联网 发布:淘宝手机店怎么开 编辑:程序博客网 时间:2024/06/04 23:35
1、linux系统编程中常用的延时函数
-sleep 、usleep 等
函数sleep 是秒延时
unsigned int sleep(unsigned int seconds);
–例如:sleep(1),即延时一秒。
–返回值:无符号的整形数值,如果延时成功则返回0,如果延时过程中被
打断,则返回剩余的秒数。例如sleep(5),返回值为3,那么实际延时就是5-3=2 秒
函数usleep 是微秒延时
int usleep(useconds_t usec);
– Useconds 需要小于1000000
–例如:usleep(10),表示延时10 微秒。
–延时成功则返回0,失败则返回-1
2、linux内核中的常用的延时函数:
-ndelay、udelay、mdelay等
3、获取机器时间函数
time_t time(time_t *t);
–参数*t:以秒为单位的机器时间
–返回值:如果参数为NULL,则返回机器时间;错误返回-1;
– time_t类型实际是一个long int类型
#include<time.h>#include<stdio.h> int main(void){time_t timep;time(&timep);printf("UTC time: 0x%08x\n", timep);timep = time(NULL);printf("UTC time: 0x%08x\n", timep);return 0;}
4、tm结构体
struct tm { int tm_sec; /* Seconds (0-60) */ int tm_min; /* Minutes (0-59) */ int tm_hour; /* Hours (0-23) */ int tm_mday; /* Day of the month (1-31) */ int tm_mon; /* Month (0-11) */ int tm_year; /* Year - 1900 */ int tm_wday; /* Day of the week (0-6, Sunday = 0) */ int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */ int tm_isdst; /* Daylight saving time */};
char *ctime(const time_t *timep);
6、将时间转化为格林威治时间
struct tm *gmtime(const time_t *timep);
7、时间转换为字符格式,注意这个函数的参数是tm 结构的
char *asctime(const struct tm *tm);
8、时间转化为本地时间
struct tm *localtime(const time_t *clock);
高精度的设置时间函数和读取时间函数
int gettimeofday(struct timeval *tv, struct timezone *tz);
int settimeofday(const struct timeval *tv, const struct timezone *tz);
–参数tv:用于保存获取的时间
–参数tz:可以缺省,传入NULL
–上面的函数比time要高6个数量级,可以达到微妙,这个精度就可以粗略的计算代码执行时间了
struct timeval { time_t tv_sec; /* seconds */ suseconds_t tv_usec; /* microseconds */ };
struct timezone { int tz_minuteswest; /* minutes west of Greenwich */ int tz_dsttime; /* type of DST correction */ };
0 0
- Linux中的延时函数
- linux延时函数
- linux延时函数
- linux延时函数
- Linux中的延时函数
- LINUX系统延时函数
- linux延时函数
- Linux中的延时函数 .
- Linux延时函数
- Linux中的延时函数
- Linux 内核延时函数
- Linux中的延时函数
- Linux中的延时函数
- linux延时函数
- linux延时函数
- linux 延时函数
- linux延时函数
- Linux中的延时函数
- 博客测试
- 二维码Data Matrix编码、解码使用举例
- [POJ3415]Common Substrings(后缀数组+单调栈)
- 使用GitHub部署网站
- 欢迎使用CSDN-markdown编辑器
- linux延时函数
- text控件限制长度
- iOS - Swift CocoaPods导入OC第三方库
- Maximum Subarray
- C++编程错误 : undefined reference to `vtable for Student'
- Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.错误解决办法
- Ueditor使用教程(高级进阶)
- C++(21):STL初步之map初步
- Vulkan学习笔记(一)-开始