Shell Process File Descriptors
SHELL PROCESS
FD 0: stdin
FD 1: stdout
FD 2: stderr
Keyboard
(Terminal)
<!-- File input -->
<rect x="50" y="250" width="80" height="40" rx="5" fill="#f39c12" stroke="#e67e22" stroke-width="2"/>
<text x="90" y="265" text-anchor="middle" font-family="Arial, sans-serif" font-size="11" fill="white">File</text>
<text x="90" y="280" text-anchor="middle" font-family="monospace" font-size="9" fill="white">< input.txt</text>
<!-- Pipe input -->
<rect x="50" y="310" width="80" height="40" rx="5" fill="#9b59b6" stroke="#8e44ad" stroke-width="2"/>
<text x="90" y="325" text-anchor="middle" font-family="Arial, sans-serif" font-size="11" fill="white">Pipe</text>
<text x="90" y="340" text-anchor="middle" font-family="monospace" font-size="9" fill="white">cmd1 | cmd2</text>
Terminal
Display
<!-- File output -->
<rect x="670" y="220" width="80" height="40" rx="5" fill="#f39c12" stroke="#e67e22" stroke-width="2"/>
<text x="710" y="235" text-anchor="middle" font-family="Arial, sans-serif" font-size="11" fill="white">File</text>
<text x="710" y="250" text-anchor="middle" font-family="monospace" font-size="9" fill="white">> output.txt</text>
<!-- Pipe output -->
<rect x="670" y="280" width="80" height="40" rx="5" fill="#9b59b6" stroke="#8e44ad" stroke-width="2"/>
<text x="710" y="295" text-anchor="middle" font-family="Arial, sans-serif" font-size="11" fill="white">Next Cmd</text>
<text x="710" y="310" text-anchor="middle" font-family="monospace" font-size="9" fill="white">cmd1 | cmd2</text>
Terminal
(Errors)
<!-- Error file -->
<rect x="670" y="420" width="80" height="40" rx="5" fill="#e67e22" stroke="#d35400" stroke-width="2"/>
<text x="710" y="435" text-anchor="middle" font-family="Arial, sans-serif" font-size="11" fill="white">Error File</text>
<text x="710" y="450" text-anchor="middle" font-family="monospace" font-size="9" fill="white">2> errors.txt</text>
<!-- /dev/null -->
<rect x="670" y="480" width="80" height="40" rx="5" fill="#34495e" stroke="#2c3e50" stroke-width="2"/>
<text x="710" y="495" text-anchor="middle" font-family="Arial, sans-serif" font-size="11" fill="white">/dev/null</text>
<text x="710" y="510" text-anchor="middle" font-family="monospace" font-size="9" fill="white">2> /dev/null</text>
FD 0
FD 1
FD 2
Common Redirection Examples:
echo "hello" > file.txt # stdout to file
ls /bad 2> errors.txt # stderr to file
sort < input.txt # stdin from file
cmd 2> /dev/null # discard errors
File Descriptor Numbers:
0 = stdin (input)
1 = stdout (normal output)
2 = stderr (error output)
Always available in every process