I'm working on my study purpose OS kernel, now I have a confusion about creating time of standard streams.
The famous "APUE" said that "By convention, UNIX System shells associate file descriptor 0 with the standard input of a process, file descriptor 1 with the standard output, and file descriptor 2 with the standard error.This convention is used by the shells and many applications; it is not a feature of the UNIX kernel."
And If I'm not mistaken, fork() and execve() won't change those opened files. Does that mean Kernel has no responsibility for preparing those standard stream for user process?(And the kernel should not do that by convention?) Does the c library source file affording program entry point such as crt.c also shouldn't do so?
From the answer under this stackexchange question, I can only make sure that POSIX.1 only requires these three streams should correspond to fileno 0, 1 and 2.
Preparing the three standard streams is generally done by the command-line shell. When a shell is about to run a program, it can fork, configure the three standard streams (connecting each to a terminal, a pipe, or a file as desired), and then use one of the exec*
functions to execute the program.