[英]Why does touch call the dup2() syscall?
这就是这个问题 。 为什么touch
调用dup2()系统调用?
$ > strace touch 1 2>&1 | tail
close(3) = 0
open("1", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 3
dup2(3, 0) = 0
close(3) = 0
utimensat(0, NULL, NULL, 0) = 0
close(0) = 0
close(1) = 0
close(2) = 0
exit_group(0) = ?
+++ exited with 0 +++
这是一件历史文物。
open()+ dup2()模式来自fd_reopen()函数,该函数由coreutils代码库中的几个程序使用。
在coreutils commit e373bb1之前,fd_reopen()没有执行open()+ dup2(),但在打开新文件描述符之前关闭了所需的文件描述符。 在coreutils commit 478bd89上使用此功能启动触摸时就是这种情况。 根据提交消息,目的是减少触摸打开的文件描述符的数量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.