Skip to main content
2 of 2
deleted 121 characters in body
the_velour_fog
  • 12.8k
  • 17
  • 74
  • 115

When a shell executes an external command/program - does that program have file descriptors?

There are alot of documents and discussion around the file descriptors of shells and how those file descriptors can be manipulated for redirection etc.
My question is, when a shell command is an external program, like rsync, cat, curl etc, do those commands have file descriptors in the same way the shell does?
To give a concrete example, if I run this command at a terminal prompt

% cat << EOF | php <?php echo "hello". PHP_EOL; echo "another line" . PHP_EOL; EOF 

I'm assuming the contents of this heredoc are being fed to STDIN, but of which process? the shell, or does cat have a file descriptor 0 and the contents of the heredoc are being fed to cat's fd0 directly?

the_velour_fog
  • 12.8k
  • 17
  • 74
  • 115