1

I'd like to know where to find the code lines that actually open the standard file descriptors (stdin, stdout, stderr) in a Linux/Glibc stack. I expect them to be in the glibc, but it would also be possible that they are written in the kernel and standard file descriptors are already open on spawning the process.

If it is in the libc, I'm specifically interested in the syscall parameters. (I assume it to be a "open" syscall.)

FYI, I want to use this as an inspiration for coding a libc for my x86 kernel.

Thanks in advance,

caylee
  • 921
  • 6
  • 12
  • Does _[this](https://stackoverflow.com/questions/6906238/where-is-stdin-defined-in-c-standard-library)_ or _[this](https://opensource.com/article/17/2/linux-boot-and-startup)_ help? (the second link points to the boot process.) – ryyker Apr 04 '18 at 14:01
  • 3
    The standard file descriptors are already open when a process starts executing. Otherwise, how would the libc know what to open? – Tavian Barnes Apr 04 '18 at 14:01
  • Thanks, I already read that post. I'm looking for the file descriptor itself, not for the FILE structure which points to fd 0,1,2. – caylee Apr 04 '18 at 14:02
  • @TavianBarnes: So the code is in the kernel? And if yes, the code is quite long to find the lines for defining the descriptors anyway. How can I find them? – caylee Apr 04 '18 at 14:06
  • @TavianBarnes: While shells typically create children with `stdin` and `stdout` already open, the reasoning you offer that this must be so because otherwise `libc` would not know what to open is invalid. Information about what to open (the terminal, a file, a pipe,…) could be passed to the child process in various ways, and the child process would then use that information to prepare the streams. – Eric Postpischil Apr 04 '18 at 14:08

0 Answers0