Duplicating (Whats Going On?)#
File Descriptors, Open File, I-Node#
File Descriptors and Inheritance#
Duplicating File Descriptors#
Example: Shell Stdout-Redirection (1)#
$ /bin/echo Hello > /dev/null
Redirection is a shell responsibility
/bin/bash
echo
writes “Hello” to standard output… and does not want/have to care where it actually goes
Example: Shell Stdout-Redirection (2)#
$ strace -f bash -c '/bin/echo Hallo > /dev/null'
[3722] open("/dev/null", O_WRONLY|O_...) = 3
[3722] dup2(3, 1) = 1
[3722] close(3) = 0
[3722] execve("/bin/echo", ...) = 0
(fork()
, exec()
, wait()
omitted for clarity.)