What is file descriptor 10?

Real-world example (where standard output is ignored, standard error redirected to standard output and data from file descriptor 10 is redirected to standard output) that I have lost the documentation/context for:

./cluexec21nodes 'mkdir /home/mortense/sambapub;cd /home/mortense/sambapub;./runcola.sh >/dev/null 2>&1 10>&1 &'

The standard file descriptors are

0   Standard Input (stdin)
1   Standard Output (stdout)
2   Standard Error (stderr)

but what is file descriptor 10?

This was used on a Linux system (possibly Red Hat).

  • 1
    Half of the command doesn't make sense. It attempts to run a script from within a directory which it just mkdir'd... – user1686 May 10 '12 at 12:47
  • @grawity: the mkdir, etc. was executed on each of a number nodes in a Linux cluster - the command enclosed in ' s. – Peter Mortensen May 10 '12 at 13:22
  • I'm aware of that. I was talking specifically about the mkdir /home/mortense/sambapub;cd /home/mortense/sambapub;./runcola.sh part. – user1686 May 10 '12 at 13:27
  • @grawity: yes, you are right. It was not well thought out (probably a mixup of two different stages). – Peter Mortensen May 10 '12 at 14:00

Beyond the standard file descriptors there are 3-1024. These can be created in scripts with the

exec 10<> afilename

From this point on, anything written to file descriptor 10 gets written to afilename

When you have

./script.sh 10>&1 

You are redirecting anything that would have gone to file descriptor 10 to stdout.

You'll want to review the runcola.sh script to see why it is doing this.

| improve this answer | |
  • The syntax is exec 10>afilename in sh. – user1686 May 10 '12 at 12:53
  • @grawity: isn't possible to redirect to another file descriptor in sh? – Peter Mortensen May 10 '12 at 13:31
  • @Paul: it may have been an arbitrary convention that was used, but given it was used for executing a command on each of a number of nodes in a Linux cluster, couldn't it have something to do with that (network pipes?). Anyway, I will try to find the two scripts. – Peter Mortensen May 10 '12 at 13:38
  • @Peter: It is, with 10>&1 or similar. – user1686 May 10 '12 at 13:56

File descriptors are not fixed; the program may use them in whatever way it wants. (Even fd's 0-2 can be closed, opened, reused.)

In this case, fd 10 seems to be chosen arbitrarily; it could be that ./runcola.sh expects to be able to write some additional information to it. You'll have to read the script itself to know for sure.

| improve this answer | |

Descriptor 10 is used for comments.

Wikipedia has a good starter article at File descriptor. It's a tiny bit misleading to say that the sh syntax "redirects" one descriptor to another. Solid sources of information may be found in "The Design of the UNIX Operating System". The documentation for the system calls dup(2) and dup2(2) reveal a good deal.

grawity, Paul, and others (you know who you are) may know of some additional resources, too. Guys?

| improve this answer | |

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.