I've been trying to learn about file descriptors. When I type ls -l /dev/fd/ I getlrwx------ 1 me users 64 May  2 16:02 0 -> /dev/pts/5l-wx------ 1 me users 64 May  2 16:02 1 -> /home/me/filelrwx------ 1 me users 64 May  2 16:02 2 -> /dev/pts/5lr-x------ 1 me users 64 May  2 16:02 3 -> /proc/31518/fd/dev/fd/3 seems to be pointing to the current process. However, explanations of file descriptors I've seen, e.g.http://www.tldp.org/LDP/abs/html/io-redirection.html, don't say there's anything special about /dev/fd/3 (and imply it's just like any /dev/fd/N for N > 3). What's going on here?I've observed this on arch linux and ubuntu, but not on the solaris server I have an ssh account on.
Something's special about /dev/fd/3
ls;file descriptors
/dev/fd/3 seems to be pointing to the current process.Ie., ls itself (notice that pid won't exist afterward).  All of those actually pertain to the current process, as file descriptors are not global; there is not just a single 0, 1, and 2 for the whole system -- there's a separate 0, 1, and 2 for each process.  As Frederik Dweerdt notes, /dev/fd is a symlink. If you repeat your ls from different terminals, you'll notice links to different ptys.  These will match the output of the tty command.In the ls example, I would imagine descriptor 3 is the one being used to read the filesystem.  Some C commands (eg, open()), which underpin the generation of file descriptors, guarantee the return of the lowest numbered unused file descriptor (POSIX -- note that low level open() is actually not part of Standard C). So they are recycled after being closed (if you open and close different files repeatedly, you will get 3 as an fd over and over again).If you want a clue about how they come to exist, here's a snippet of C code using opendir(), which you'll probably find in the source for ls:// open directory for readingDIR *dh = opendir(.);// print the fd of the directory handle to standard out:printf(fd: %d\n, dirfd(dh));closedir(dh);  Run as is, the fd will be 3, since that is the lowest unused descriptor (0, 1, and 2 already exist).