你如何获得clock_gettime(2)时钟在shell?

你如何获得clock_gettime(2)时钟在shell?,第1张

概述你如何获得clock_gettime(2)时钟在shell?

我没有看到这样的select

/proc/uptime基于bootbased,不是单调的。

最后我发现了cat /proc/timer_List | grep Now cat /proc/timer_List | grep Now产生ktime_get数量,这是通过ktime_get获得,这是返回单调时间,如果我理解正确,但这是相当繁琐的。

更新:返回的值必须与clock_gettime返回的值相同

系统时间,本地时间,文件时间和正常时间

GetThreadtimes会给出奇怪的结果

windows XP的本地时间夏令时问题

将时间跨度转换为shell中的格式化时间

如何以毫秒分辨率获得windows系统时间?

在windows上将时间string转换为纪元时间

以编程方式计算windows上的进程的开始时间

比较两次在宽容内的平等吗?

为什么clock_gettime如此不稳定?

谁改变了时间?

看起来像在Python 3.3中可用: http : //www.python.org/dev/peps/pep-0418/

如果没有,你可以写一个小的C程序,调用clock_gettime : http : //linux.dIE.net/man/3/clock_gettime

如果每次写出完整的行,咨询/proc/uptime只是很麻烦。 为什么不把它包起来呢?

$ alias Now="awk '/^Now/ {print $3; exit}' /proc/timer_List" $ Now 396751009584948

这也避免了无用猫的使用。

更新

请在阅读之前阅读此问题:在提问之前发布了此答案,并添加了clock_gettime要求。 所以我花了很多时间写作,和作者一起讨论,澄清了他的要求之后,我赢得了三个(刚得到新的)不公平的赞誉。 我保留这一点,尽管有些倒退,因为它似乎对一些人有用。 毕竟,如果你决定冷静下来,你至少能说出你的理由吗?

在shell中,您可以使用date实用程序:

date +%s.%N date +%s%N nanoseconds_since_70=$(date +%s%N)

从男人约会:

%s seconds since 1970-01-01 00:00:00 UTC %N nanoseconds (000000000..999999999)

毫微秒部分以正确的方式补充了秒:当%N从999999999变为0时,%s递增1秒。 我没有这方面的参考(请编辑,如果你能找到它),但只是工作。

日期实用程序x clock_gettime

请注意,该号码不受时区变化的影响,但会受到系统时钟更改的影响,如系统管理员所做的更改,NTP和定时功能。 但clock_gettime函数中的CLOCK_MONOTONIC也受到影响,管理员更改除外。

CLOCK_MONOTONIC -- Clock that cannot be set and represents monotonic time since some unspecifIEd starting point. This clock is not affected by discontinuous jumps in the system time (eg,if the system administrator manually changes the clock),but is affected by the incremental adjustments performed by adjtime(3) and NTP.

较新的系统有一个更好的解决方案:CLOCK_MONOTIC_RAW。 尽管如此,这是一个按要求的解决方案。

了解更多

单调功能在维基百科

@caf用户来自CLOCK_REALTIME和CLOCK_MONOTONIC之间的区别? :

CLOCK_MONOTONIC represents the absolute elapsed wall-clock time since some arbitrary,fixed point in the past. It isn't affected by changes in the system time-of-day clock. If you want to compute the elapsed time between two events observed on the one machine without an intervening reboot,CLOCK_MONOTONIC is the best option.

总结

以上是内存溢出为你收集整理的你如何获得clock_gettime(2)时钟在shell?全部内容,希望文章能够帮你解决你如何获得clock_gettime(2)时钟在shell?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1288491.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存