17
$ ls -og /proc/self /proc/self/fd
lrwxrwxrwx 1 64 Jun 18 11:12 /proc/self -> 32157

/proc/self/fd:
total 0
lrwx------ 1 64 Jun 22  2012 0 -> /dev/tty1
lrwx------ 1 64 Jun 22  2012 1 -> /dev/tty1
lrwx------ 1 64 Jun 22  2012 2 -> /dev/tty1
lr-x------ 1 64 Jun 22  2012 3 -> /proc/32157/fd

What is the file descriptor 3 assigned by default?

31

Nothing: there are three standard file descriptions, STDIN, STDOUT, and STDERR. They are assigned to 0, 1, and 2 respectively.

What you are seeing there is an artifact of the way ls(1) works: in order to read the content of the /proc/self/fd directory and display it, it needs to open that directory.

That means it gets a file handle, typically the first available ... thus, 3.

If you were to run, say, cat on a separate console and inspect /proc/${pid}/fd for it you would find that only the first three were assigned.

  • Ah, that explains the result, including the fact that 3 points to /proc/32157/fd as well. (Why did I miss that?) Thank you! – musiphil Jun 23 '12 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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