在我的linux系统上,如果我显示当前日期" t1 ",那么触摸一个文件"f“,然后显示该"f”的修改时间" t2“,我希望t1
但当我在我的系统上执行这个时,我并不总是这样:
date +'%Y-%m-%d %H:%M:%S.%N'; \
touch f; \
stat -c %y f
示例输出:
2017-09-18 21:47:48.855229801
2017-09-18 21:47:48.853831698 +0200
注意,第二个时间戳(stat)位于第一个时间戳(日期)之前: 855229801 > 853831698
我的fs是ext4,但我也尝试在tmpfs上使用一个文件,效果相同。为什么是这种情况?
谢谢
关于设置的一些信息
% which date
/usr/bin/date
% which touch
/usr/bin/touch
% pacman -Qo /usr/bin/date /usr/bin/touch
/usr/bin/date is owned by coreutils 8.28-1
/usr/bin/touch is owned by coreutils 8.28-1
% uname -a
Linux machine 4.12.12-1-ARCH #1 SMP PREEMPT Sun Sep 10 09:41:14 CEST 2017 x86_64 GNU/Linux
% findmnt
TARGET SOURCE FSTYPE OPTIONS
/ /dev/sda1 ext4 rw,relatime,data=ordered
└─/tmp tmpfs tmpfs rw,nosuid,nodev发布于 2017-09-18 21:37:00
根据https://stackoverflow.com/questions/14392975/timestamp-accuracy-on-ext4-sub-millsecond:
ext4文件系统代码调用
current_fs_time(),这是当前缓存的内核时间被截断到文件系统的超级块( ext4为1ns )中指定的时间粒度。Linux内核中的当前时间是缓存的,通常只在计时器中断上更新。因此,如果您的计时器中断以10毫秒的速度运行,则缓存时间将仅每10毫秒更新一次。当发生更新时,结果时间的准确性将取决于硬件上可用的时钟源。
https://unix.stackexchange.com/questions/393056
复制相似问题