Shouldn't the standard input for different process unique? If so, shouldn't the path of the stdin file be like /dev/pid/stdin
instead of a global /dev/stdin
?
Does anyone have ideas about this?
Every process is initialized with three open file descriptors called stdin , stdout , and stderr .
/dev/stdin is a symlink to /proc/self/fd/0 , convenient here because of $(< .. ) syntax which expects a file. this could cause a problem because the command may be blocked until stdin closed. it is safe in the meaning that multiline input will be preserved because au double-quotes.
There aren't multiple stdout, stdin and stderr channels; there's only one of each, assigned by the operating system itself. It's possible to redirect stdin, stdout and stderr to different targets on a process by process basis, but it's all handled by the operating system.
stdin / stdout are logical names for open files that are forwarded (or initialized) by the process that has started a given process. Actually, with the standard fork-and-exec pattern the setup of those may occur already in the new process (after fork) before exec is being called.
/dev/stdin
is unique because
/proc/self/fd/0
/proc/self
is a symbolic link only seen by your running process to its process-idThe /proc
filesystem is a virtual (not real) filesystem which has the ability to show a different view to each process.
Further reading:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With