I have noticed that when I run
ls /proc/self/fd
I get the following output:
0 1 2 3 47
Obviously, 0, 1 and 2 are the descriptors for stdin, stdout and stderr, respectively, and 3 is the descriptor which ls uses to access the directory.
But what is 47? It must be something passed by the shell (and not something specific to ls) because running cat outputs:
$ cat /proc/self/fd/47
cat: /proc/self/fd/47: Permission denied
# example of running cat on a non-existent file descriptor
$ cat /proc/self/fd/46
cat: /proc/self/fd/46: No such file or directory
ls -l says that it is connected to anon_inode:inotify.
I am using Arch Linux with KDE, and this seems to matter, because it doesn't seem to happen if I run commands from tty. It's not shell specific (it happens on both bash and zsh), though it may be terminal specific (I am using Konsole). Regardless, isn't the shell supposed to close every descriptor except 0-2 before exec (or have them flagged with O_CLOEXEC)?
I am running KDE Plasma 5.27.10.
EDIT: Since sudo closes all descriptors except 0-2, I tested sudo konsole, and the instance of zsh inside this new terminal doesn't leak descriptor 47 into new processes. This means that there's nothing wrong with Konsole itself, but that it receives the descriptor from its parent (which appears to be plasmashell).
kde-plasma5.27.10,kde-framework55.114.0 andqt5-base5.15.12 (from pacman). EDIT:qt5-webengine5.15.16sudo lsof -d 47may help spot which process in your shell's ancestry has opened that fd and forgot to mark it with the close-on-exec flag (or close it before executing another command).