Questions: File Descriptor Tables and I/O Redirection

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

When a shell executes `ls > output.txt`, which sequence of operations does the child process perform before running `ls`?

AIt modifies the `ls` binary to write to a file instead of the terminal
BIt closes file descriptor 1, then opens output.txt — which receives fd 1 as the lowest available slot
CIt opens output.txt as a new file descriptor and passes that number as an argument to `ls`
DIt tells the kernel to intercept `ls`'s output and redirect it to the file
Question 2 Multiple Choice

When the shell sets up a pipe for `ls | grep foo`, what does it actually create?

AA temporary file that `ls` writes to and `grep` reads from sequentially
BA shared memory region that both processes access concurrently
CA kernel buffer with a write-end file descriptor wired to `ls`'s stdout and a read-end wired to `grep`'s stdin
DA network socket connecting the two processes through the loopback interface
Question 3 True / False

The kernel enforces that file descriptor 1 usually refers to the terminal (stdout), which is why programs can rely on writing to fd 1 to display output.

TTrue
FFalse
Question 4 True / False

When a process is created via fork(), the child process inherits a copy of the parent's file descriptor table.

TTrue
FFalse
Question 5 Short Answer

Why can `ls > output.txt` redirect ls's output to a file without any modification to the `ls` source code?

Think about your answer, then reveal below.