What does all this stuff mean?
/proc
is a filesystem through which the kernel reports various information to processes. It's mostly for information about processes, hence the name “proc[esses]”. For each running process, there's a subdirectory /proc/<PID>
where <PID>
is the process ID.
/proc/self
is a “magic” symbolic link that always points to the process that's accessing /proc
.
/proc/self/fd
reports the files opened by a process. Each entry is a “magic” symbolic link whose name is the file descriptor and whose target is the open file. It's magic in the sense that the link actually points to the file itself, even if the file name obtained by calling readlink
is not a valid file name, which happens, for example, with files that don't have a name (such as anonymous pipes and sockets), and with deleted files.
lrwx------ 1 username username 64 Nov 8 19:01 0 -> /dev/pts/6
lrwx------ 1 username username 64 Nov 8 19:01 1 -> /dev/pts/6
lrwx------ 1 username username 64 Nov 8 19:01 2 -> /dev/pts/6
lrwx------ 1 username username 64 Nov 8 19:01 3 -> 'socket:[8239772]'
lr-x------ 1 username username 64 Nov 8 19:01 4 -> /proc/29512/fd/
How do floppy disks work here?
No floppy disks are involved. The abbreviation “fd” stands for file descriptor.
What is /dev/pts/6
, and why do 0
, 1
, and 2
all point to it?
File descriptors 0
, 1
and 2
are the three standard streams) that all programs expect to find: standard input (stdin), standard output (stdout) and standard error (stderr). These streams are defined by their number: stdin is file descriptor 0 by definition, and its conventional role is to receive user input or input data, and likewise for stdout (1, user output or output data) and stderr (2, error messages).
/dev/pts/6
is a terminal. It's the file that processes use to read input from, and write output to, that particular terminal. When you run a program “normally” in a terminal, stdin, stdout and stderr are all connected to the terminal.
What is 'socket:[8239772]'
?
It's a socket. File descriptor 3 has no standard role, so it's specific to some software you're using, maybe your terminal emulator. You can see what's on the other end of the socket if you're curious.
What is /proc/29512/fd/
?
When you run ls /proc/self/fd/
, the ls
program opens /proc/self/fd
to read its contents. Since file descriptors 0 to 3 are already open when ls
starts, and open
uses the first available file descriptor, /proc/self/fd
ends up being open on file descriptor 4. It appears with the PID because the kernel doesn't keep track of accesses through /proc/self
internally: it remembers them as a particular process's /proc
directory, which it then prints out using the correct PID. (With PID namespaces, that PID, and hence the path, can be different depending on which process is looking.)
What is the historical use of and description for /dev/fd
?
It's useful when programs need a file name and you want to refer to a file that's already open. It's a generalization of /dev/stdin
, /dev/stdout
and /dev/stderr
which are equivalent to /dev/fd/0
, /dev/fd/1
and /dev/fd/2
respectively (and existed before the more general /dev/fd
appeared). It's available on many unix variants.
fd
in/dev/fd
means "floppy disk". Ex: here and here, so it is confusing to say the least. This still isn't clear. I wonder iffd
originally meant "floppy disk" and then gradually came to mean "file descriptor" when floppy disks went out of use. Also, my question goes way beyond that, and beyond what the other answers contain. – Gabriel Staples Nov 09 '21 at 02:26/dev/fd0
that's the floppy, not/dev/fd
.fd
!=fd0
. I'm pretty sure Unix on the PDP-11 predates floppy disks. – muru Nov 09 '21 at 02:37fd 0 0 0 0% /dev/fd
given as output ofdf -k
. (A more complete output here.) That looks similar to thedf -k
output on Linux in that the first field is the device and the last is the mount point. With the device called justfd
, and not/dev/...
and sizes shown as zeroes, I'd be willing to bet it's a virtual filesystem that's the Solaris equivalent of Linux's/proc/*/fd
, and nothing to do with floppies. – ilkkachu Nov 09 '21 at 17:57