Linux proc / pid / fd for stdout是11?
发布时间:2020-12-13 19:48:46 所属栏目:Linux 来源:网络整理
导读:执行stdout重定向到文件的脚本.所以/ proc / $$/ fd / 1应指向该文件(因为stdout fileno为1).但是,文件的实际fd是11.请解释,为什么. 这是会议: $cat hello.sh#!/bin/sh -els -l /proc/$$/fd 2$./hello.sh /tmp/1total 0lrwx------ 1 nga users 64 May 28 22
执行stdout重定向到文件的脚本.所以/ proc / $$/ fd / 1应指向该文件(因为stdout fileno为1).但是,文件的实际fd是11.请解释,为什么.
这是会议: $cat hello.sh #!/bin/sh -e ls -l /proc/$$/fd >&2 $./hello.sh > /tmp/1 total 0 lrwx------ 1 nga users 64 May 28 22:05 0 -> /dev/pts/0 lrwx------ 1 nga users 64 May 28 22:05 1 -> /dev/pts/0 lr-x------ 1 nga users 64 May 28 22:05 10 -> /home/me/hello.sh l-wx------ 1 nga users 64 May 28 22:05 11 -> /tmp/1 lrwx------ 1 nga users 64 May 28 22:05 2 -> /dev/pts/0 解决方法
我怀疑,但这在很大程度上取决于你的shell的行为方式.您看到的文件描述符是:
> 0:标准输入 描述符10和11在exec上是关闭的,因此不会出现在ls进程中.然而,在分叉之前为0s准备了0-2.我在破折号(Debian Almquist shell)中看到了这种行为,但在bash(Bourne再次shell)中却没有. Bash反而在分叉后执行文件描述符操作,并且顺便使用255而不是10用于脚本.在分叉后执行更改意味着它不必恢复父级中的描述符,因此它没有备份副本到dup2. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |