1

Each process uses a set of open files in linux . Now bash ( a shell ) is also a process which uses different file descriptor for standard input output. If I find some file descriptors :

ls -l /proc/$$/fd  

lrwx------ 1 viky viky 64 Jan 15 16:29 0 -> /dev/pts/0
lrwx------ 1 viky viky 64 Jan 15 16:29 1 -> /dev/pts/0
lrwx------ 1 viky viky 64 Jan 15 16:29 2 -> /dev/pts/0
lrwx------ 1 viky viky 64 Jan 15 16:30 255 -> /dev/pts/0

Now , the 0,1,2,255 are file descriptors . Now , if we see here 0,1,2 is pointing to my current terminal ( taking input from terminal and showing output and error to terminal ). The question is , what is the role of stdin ( /dev/stdin ), stdout ( /dev/stdout ) and stderr ( /dev/stderr ) . 0,1,2 are default standard streams for stdin , stdout and stderr .

How standard streams are related to the ouput of above command ?

lets say , file descriptor for /dev/stdin is 0 . So is /dev/stdin link to /dev/pts/0 for the bash process. ?

can anyone explain in detail pls .

4
  • I guess you have already answered in your question what is the role of these descriptors - these are stdin, stdout and stderr. Could you please clarify what exactly is your question?
    – raj
    Commented Jan 15, 2021 at 11:19
  • lets say , file descriptor for /dev/stdin is 0 . So is /dev/stdin link to /dev/pts/0 for the bash process. ? Commented Jan 15, 2021 at 11:35
  • As you can see by ls command, /dev/stdin is a link to /proc/self/fd/0 (at least in case of Debian). And /proc/self/fd/0 is a link to /dev/pts/0. So /dev/stdin is not directly a link to /dev/pts/0. It is a link to the descriptor, and the descriptor is a link to /dev/pts/0.
    – raj
    Commented Jan 15, 2021 at 11:42
  • Detailed answer at unix.stackexchange.com/questions/400849/…. Commented Jan 16, 2021 at 3:16

0

You must log in to answer this question.

Browse other questions tagged .