Search code examples
clinuxstdinfile-descriptordescriptor

Why standard inputs are not mixed in linux?


We know that each process has set three descriptors in advance:

0 (stdin), 1 (stdout), 2 (stderr)

Why stdin between different processes are not mixed ? After all, each process has the same descriptor equals to 0. Can anyone explain it ?


Solution

  • Each process has its own set of file descriptors. File descriptor 0 of one process doesn't necessarily reference the same file handle as file descriptor 0 of another process.

    Same goes for memory addresses. Because of memory virtualization, each process has its own address space. Different process can use the same address for different purposes.