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 .
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
.