TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Opening /proc/self/fd/1 is not the same as dup(1)

61 点作者 gnoack超过 1 年前

4 条评论

kazinator超过 1 年前
Obscure fact #37: Glibc&#x27;s implementation of <i>freopen</i> opens &#x2F;proc&#x2F;self&#x2F;fd&#x2F;&lt;n&gt;, when the pathname is null, e.g.:<p><pre><code> freopen(NULL, &quot;w&quot;, stdout);</code></pre>
tsimionescu超过 1 年前
Doesn&#x27;t the Linux behavior make more sense? It basically guarantees that open() always returns a new file description. Having open() return an existing file description for some special files seems like a recipe for exploits. Dup() already exists for this purpose.
评论 #39446289 未加载
评论 #39441788 未加载
Joker_vD超过 1 年前
&gt; Unix processes have <i>file descriptors</i> which point to <i>file descriptions</i> (`struct file` in Linux).<p>Also known as <i>file handles</i> referencing <i>file objects</i> (on Windows). Unix terminology is unnecessarily confusing in this place IMHO.<p>On the subject of the article itself: why was this change introduced? To give kernel support for reopen(3) since dup(3) already exists?
评论 #39440014 未加载
评论 #39443075 未加载
larsnystrom超过 1 年前
I can&#x27;t be the only one who dreams of a radically different successor to Linux when I read stuff like this. Like, why do I need to care about file descriptors? Why is everything a file, except its not because it can be a socket, or a pipe, or a block device, or something else I haven&#x27;t heard about? Why does the OS even care what my current working directory is? How are we ever going to get rid of C when the whole OS interface is defined in C? Even with the simplest program, running in a single thread (or is it pthread?), I can&#x27;t control the flow of execution because suddently SIGNALS happen and who knows what&#x27;ll happen then. Like, you could use select(2), but you should use pselect(2) to deal with signals, except select(2) should not be used because it can&#x27;t deal with PIDs larger than 1024, so use poll(2), or maybe epoll(7), or ppoll(2) if you want to deal with signals, but what happens when you use epoll(7) and have to deal with signals? And did you notice all those numbers next to the syscall names? Wait, what do you mean syscall, is it not a function? And of course, to create a new process, you use a syscall called fork(), because processes and cutlery are intrinsically linked.<p>Honestly, the OS situation is a mess and I just want to not think about it, but not having an OS is not really an option.
评论 #39440115 未加载
评论 #39440499 未加载
评论 #39439619 未加载
评论 #39440062 未加载
评论 #39440070 未加载
评论 #39439474 未加载
评论 #39439537 未加载
评论 #39440571 未加载
评论 #39441136 未加载