linux - 为什么 stat mtime 每秒只更新两次?

标签 linux r stat

更新

下面的 bash 命令行似乎表明它不是 R 问题(玩一下 sleep 看看它只会在每秒 0.43 和 0.93 后更新)。 (所以我更改了问题标签。)

touch tmp.txt;stat tmp.txt;sleep 0.5;touch tmp.txt;stat tmp.txt

但是我看到“修改:2013-06-20 14:28:36.938579054”,而不是“修改:2013-06-20 14:28:36”,这表明我的 linux 内核已编译并配置为纳秒级精度。所以,我仍然有点困惑,为什么它看起来与纳秒级精度相去甚远!


下面的脚本隔离了我在真实脚本中发现的一个问题。我将数据反复保存到同一个文件中。似乎 file.info$mtime 每秒只更新两次。当我使用 0.05s sleep 时,问题非常明显:file.info 没有更新 100 次中的 87 或 88 次。如果我将 sleep 时间增加到 0.5s,它会完美运行(坏 ==0 ).如果我将 sleep 时间减少到 0.4 秒,则 100 次中有 14 次出错。

我的问题是:这是一个 R 错误,还是与操作系统有关?还是我做错了什么,或者做出了错误的假设?

我在 Ubuntu 10.04 上使用 R 3.0.1。

顺便说一句,我在运行下面的代码时注意到,mtime 总是以 .936 或 .436(或非常接近它们的值)结尾。绝不是 0.250、0.800 或 0.950 等。

另一个可能有用的数据点:我尝试在每次调用 save 之前执行 file.remove。没有区别。

fname="tmp.rdata"
options(digits.secs = 3)

data=runif(100)
save(list=c("data"),file=fname)
info=file.info(fname)

ix=0;bad=0

while(ix<100){
    Sys.sleep(0.05)
    data=runif(100)
    current=Sys.time()
    save(list=c("data"),file=fname)
    info2=file.info(fname)
    if(info2$mtime<=info$mtime){bad=bad+1;cat("****************\n")}
    print(current);print(rbind(info,info2))
    ix=ix+1;info=info2
    }
cat("bad=",bad,"\n")

这是过去两个月的文件的 stat -c "%y"* |sort 的输出。所以看起来日期可以在第二个的任何地方。然而,对于大约同时保存的文件,它们似乎都具有相同的两个值?!

2013-04-16 14:41:50.331227602
2013-04-19 20:52:50.238225648
2013-04-30 10:34:43.896278930
2013-05-02 08:36:39.360523004
2013-05-02 08:46:07.848039045
2013-05-07 17:10:19.372043866
2013-05-07 19:12:00.369502114
2013-05-07 19:19:11.370293101
2013-05-07 22:14:39.744755951
2013-05-07 22:14:58.242163170
2013-05-24 12:21:06.231306593
2013-06-06 15:14:40.174142594
2013-06-10 11:16:31.958667081
2013-06-10 11:18:29.958090098
2013-06-10 11:34:16.961026520
2013-06-12 10:44:12.825080955
2013-06-14 12:50:49.531729270
2013-06-17 11:05:23.792289000
2013-06-18 11:44:40.347221361
2013-06-19 13:10:46.590013564
2013-06-20 11:52:16.436423344
2013-06-20 11:52:24.437938646
2013-06-20 11:52:24.437938646
2013-06-20 13:17:16.436666359
2013-06-20 13:20:50.928713629
2013-06-20 14:28:36.938579054

最佳答案

如果您每秒获得两次更新,那么您实际上做得很好。 R-project reference 第 227 页的摘录关于 file.info:

What is meant by the three file times depends on the OS and file system. On Windows native file systems ctime is the file creation time (something which is not recorded on most Unix-alike file systems). What is meant by ‘file access’ and hence the ‘last access time’ is system-dependent.

The times are reported to an accuracy of seconds, and perhaps more on some systems. However, many file systems only record times in seconds, and some (e.g. modification time on FAT systems) are recorded in increments of 2 or more seconds

关于linux - 为什么 stat mtime 每秒只更新两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17205235/

相关文章:

r - 文本分类-当训练数据和测试数据具有不同特征时该怎么办

r - 查找数据框中两列元素之间的差异

linux - 如何从后台进程 linux shell 脚本中获取结果?

linux - 如何通过linux终端复制网页内容到文件中?

r - 将文件加载到 R

linux - mv命令移动文件,但报告错误: cannot stat no such file or directory

linux - 进程锁定的文件的未定义时间戳

c - 如何使用递归获取 C 中文件夹的总大小?

java - 在谷歌云实例 rhel7 中导出变量

linux - 将时间跨度(以秒为单位)转换为 shell 中的格式化时间