linux获取应用程序时钟,linux – 你如何在shell中获得clock_gettime(2)时钟?

这不回答当前的问题,但回答了原来的问题.因此,它一直被保留,因为它对目前为止的一些人有用.

在shell中你可以使用日期工具:

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增加一秒.我没有参考(请编辑,如果你能找到它),但只是工作.

date utility 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 (e.g., if the system administrator

manually changes the clock), but is affected by the incremental adjustments

performed by adjtime(3) and NTP.

较新的系统有更好的解决方案:CLOCK_MONOTIC_RAW.尽管如此,这是一个shell解决方案.

了解更多

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值