file descriptors
Hi
I'm using debian with xfce4-terminal. Code:
ls /dev/fd 2. if I close fd 3 the terminal closes - why?. I didn't "open" fd 3 manually for reading/writing so it's not clear why is it even enabled. Thanks |
Because these are not files as such: https://www.baeldung.com/linux/dev-directory
|
The answer which is perfectly correct and yet totally irrelevant... On my system (kubuntu) there is no such nonsense:
Code:
lrwx------ 1 x x 64 Dec 14 08:54 0 -> /dev/pts/12 |
Quote:
Based on your post fd=0 is still inherited, fd=1 is redirected into a pipe, fd=2 is still the original one. The last one, fd=3 is usually belongs to the "current process". In your case that is the command ls. It opened /dev/fd (as you specified), which is a symbolic link to /proc/self/fd, which is in turn a hard link to /proc/<pid>/fd. That is what you see as 3 -> /proc/94877/fd, ls opened that dir to list its content. Additionally fd=3 belongs to the process ls, not to the shell. The current shell may have also a fd=3 opened, but we don't know (depends on how did you start/use it). Closing it probably terminates your shell and at the end that will also force close its parent process, the terminal itself. |
The pathname /dev/fd appears to be global, in common to all processes.
If you find things in it that are specific to a certain process then examine the parent directory Code:
ls -ld /dev/fd "self" points to the current process. Code:
ls -ld /proc/self Use the shell-internal cd command to safely examine the shell itself: Code:
echo "My pid is $$" Code:
ls -l /proc/self/fd |
Code:
$ echo $$ |
Thanks for the replies.
But why is fd 1 (=standard output) symlinked to a process?. |
that is not symlinked, but piped to somewhere. It depends on how did you start your terminal and shell, what is running inside.
here is a link to check what is using that pipe: https://stackoverflow.com/questions/...a-bash-command |
All times are GMT -5. The time now is 03:18 PM. |