In Linux, why is there a global /dev/stdin file for all processes?

左心房为你撑大大i 提交于 2019-12-18 05:59:20

问题


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?


回答1:


/dev/stdin is unique because

  • it is a symbolic link to /proc/self/fd/0
  • /proc/self is a symbolic link only seen by your running process to its process-id

The /proc filesystem is a virtual (not real) filesystem which has the ability to show a different view to each process.

Further reading:

  • Linux Filesystem Hierarchy: 1.14. /proc
  • Red Hat Enterprise Linux 3: Reference Guide: Chapter 5. The proc File System


来源:https://stackoverflow.com/questions/36615360/in-linux-why-is-there-a-global-dev-stdin-file-for-all-processes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!