Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Are file descriptors unique across a process, or throughout the whole system. Because every file seems the use the same descriptor for stdin and stdout. Is there something special with these? How does stdin and stdout work? I realize the dev/fd, is a link to proc/self/fd, but how do they all have the same number?

Edit: Even after looking at other processes most of the file descriptors are about the same numbers.

share|improve this question
See also unix.stackexchange.com/questions/24145/… and other questions tagged file-descriptors. – Gilles Dec 16 '11 at 8:24
up vote 6 down vote accepted

Several things might be confusing here.

Filedescriptors are attached to a file (in the general sense) and are specific to a given process. Filedescriptors are themselves referred to via numeric ids by their associated process, but one file descriptor can have several ids. Example: ids 1 and 2 which are called standard output and standard error usually refers to the same file descriptor.

The symlinks /proc/pid/fd/x only provide a hint for what the x filedescriptor of process pid is linked to. If it's a regular file, the symlink gives its path. But if the filedescriptor is e.g. an inet socket, then the symlink is just broken. In the case of a regular file (or something which has a path like a tty), it's possible to open it, but you would obtain a different filedescriptor to the same object.

share|improve this answer
Cool, thank you :-) – rubixibuc Dec 16 '11 at 0:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.