Is redirection a concept of the shell, not of the OS kernel?
How is redirection implemented in terms of system calls?
Is redirection implemented similarly to pipe?
Is redirection a concept of the shell, not of the OS kernel?
How is redirection implemented in terms of system calls?
Is redirection implemented similarly to pipe?
For redirection, I would assume this (redirection) is implemented by the shell replacing stdin (by input for < input) and stdout (by output for > output) using dup2() -
For pipe, the pipe(2) system call is used in a similar way - this has a read and a write end. Each command that is connected via the pipe would read from one end of a pipe and write to the other end. stdin, stdout will replace the corresponding end of the pipe for that command.
"redirection" is a concept of the shell, and the details around it depend on which shell you are talking about.
Though, one might say that the basis for redirection rests with the notion that programs have pre-opened input and output file descriptors when they start, which traces back to how the execve
function works. Namely that the child process inherits opened file descriptors.
Thus, to start a child (a command), the parent process (i.e., the shell) will first fork for the child to be, then set up appropriate pipe ends for the child's input and output (file descirptors 0, 1 and 2), and then let the child inherit those when executed via execve
.
Yes, it's pipes.