获取Linux时间函数
Linux下clock_gettime函数详解
要包含这头文件<time.h>
且在编译链接时需加上 -lrt ;因为在librt中实现了clock_gettime函数。
---
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC,ts);
printf("%d %d",ts.tv_sec, ts.tv_nsec);打印出来的时间跟 cat /proc/uptime第一个参数一样
/proc/uptime里面的两个数字分别表示:
the uptime of the system (seconds), and the amount of time spent inidle process (seconds).
把第一个数读出来,那就是从系统启动至今的时间,单位是秒
Middleware对POSIX提供的标准计时器API进行封装,主要提供了两种类型的时钟的封装。一种是CLOCK_REALTIME,另一种是CLOCK_MONOTONIC。对与man手册的解释是:
CLOCK_REALTIME: Systemwide realtime clock. 系统范围内的实时时钟。
CLOCK_MONOTONIC:Represents monotonic time. Cannot be set.表示单调时间,不能被设置的。
手册中解释的比较笼统。我个人的理解是:
CLOCK_REALTIME:这种类型的时钟可以反映wall clocktime,用的是绝对时间,当系统的时钟源被改变,或者系统管理员重置了系统时间之后,这种类型的时钟可以
得到相应的调整,也就是说,系统时间影响这种类型的timer。
CLOCK_MONOTONIC:用的是相对时间,他的时间是通过jiffies值来计算的。该时钟不受系统时钟源的影响,只受jiffies值的影响。
建议使用:
CLOCK_MONOTONIC这种时钟更加稳定,不受系统时钟的影响。如果想反映wall clocktime,就使用CLOCK_REALTIME。
clock_gettime比gettimeofday更加精确
clock_gettime( )提供了纳秒的精确度,给程序计时可是不错哦;
获取Linux时间函数的更多相关文章
- [javascript]获取系统时间函数
var oDate=new Date(); //初始化系统时间函数 alert(oDate.getHours()); //获取时 alert(oDate.getMinutes()); //获取分 al ...
- Linux时间函数
一.时间编程 1.核心理论 (1).时间类型 2.函数学习 (1).获取日历时间 函数名:time 函数原型:time_t time(time_t *t) 函数功能:获取当前日历时间 所属头文件:&l ...
- round函数和获取当前时间函数
round函数:对一个浮点类型的数据进行四舍五入:round(3.14) 运行结果就是3 获取当前时间: time.time() ,time函数需要导入才能使用,import time
- Mysql 获取当前时间函数 (类似于sql server 中的 getDate())
1 获得当前日期+时间(date + time)函数:now() 2 获得当前日期+时间(date + time)函数:sysdate() sysdate() 日期时间函数跟 now() 类似,不同之 ...
- linux 下的clock_gettime() 获取精确时间函数
#include <time.h> int clock_gettime(clockid_t clk_id, struct timespec* tp); clock_gettime() 函数 ...
- Linux时间函数之gettimeofday()函数之使用方法
1.简介: 在C语言中可以使用函数gettimeofday()函数来得到时间.它的精度可以达到微妙 2.函数原型: #include<sys/time.h> int gettimeofda ...
- 【转】Linux时间函数之gettimeofday()函数之使用方法
原文网址:http://blog.csdn.net/tigerjibo/article/details/7039434 一.gettimeofday()函数的使用方法: 1.简介: 在C语言中可以使用 ...
- c/c++获取系统时间函数
参考:http://blog.sina.com.cn/s/blog_6f2caee40100uu41.html Coordinated Universal Time(UTC): 协调世界时,又称为 ...
- linux几种时间函数总结
一.linux时间函数总结 最近的工作中用到的时间函数比较频繁,今天抽时间总结一下,在linux下,常用的获取时间的函数有如下几个: asctime, ctime, gmtime, localti ...
随机推荐
- 构建Maven项目时常见错误
一.Maven项目,右键-update project后JRE system Library变为JavaSE1.6 Dynamic Web Module 3.0 requires Java 1.6 o ...
- POJ--3321 Apple Tree(树状数组+dfs(序列))
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22613 Accepted: 6875 Descripti ...
- Anaconda中配置Pyspark的Spark开发环境
1.windows下载并安装Anaconda集成环境 URL:https://www.continuum.io/downloads 2.在控制台中测试ipython是否启动正常 3.安装JDK 3.1 ...
- 【转】(翻译)从底层了解ASP.NET体系结构
原文地址:http://www.cnblogs.com/rijing2004/archive/2007/09/14/howaspnetwork.html 前言关于ASP.NET的底层的工作机制,最近园 ...
- python字典获取最大值的键的值
有时我们需要字典中数值最大的那个键的名字,使用max(dict, key=dict.get)函数非常的方便 key_name = max(my_dict, key=my_dict.get) 获取之后你 ...
- os.path 模块
os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...
- angularjs中的单选框绑定数据注意事项
这里说的是angularjs 1.x 在实现单选框时,我们完全可以用html自带的<input type="radio"/>,但是配合angularjs 中的双向绑定, ...
- PHP漏洞
http://os.51cto.com/art/201204/328766.htm 针对PHP的网站主要存在下面几种攻击方式: 1.命令注入(Command Injection) 2.eval注入(E ...
- 最大生成树——LCA
今天说是要练习LCA结果找了道题看着题解打完了,如此惭愧,Lca还得好好理解啊,感觉在最大生成树上做有点异样,可能还是不是很理解吧,在noip前一定要再把这道题再a一遍,好题啊. 这是2013noip ...
- Silver Cow Party---poj3268(最短路,迪杰斯特拉)
Silver Cow Party Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u De ...