2 ms·
This looks entirely wrong to me? The stdin file descriptor isn't "owned" by or associated with the parent process at all. It's whatever the parent decided to
by ajross 3y ago
This looks entirely wrong to me? The stdin file descriptor isn't "owned" by or associated with the parent process at all. It's whatever the parent decided to set up at fork time, and by default it's just "whatever the parent's parent set up for IT". That is absolutely not guaranteed to be closed when the parent exits.
It's true that if you spawn something interactively from the shell and kill it, the shell will clean up the file descriptors before returning to read the next command. And that will look like a close to any children that might have launched. But redirect stdin from a real file and no such close is going to happen. Likewise launcher tools like systemd that want to parse the process output and control it have behavior that tends not to be shell-like.
- tedunangst 3y agoI think the article is unclear. The pattern is to create a pipe and hook that up to stdin.