# 2015-07-19 Today I finally understood a riddle given to me 3-4 years ago. The person I was talking to at the time had just talked to a friend who supposedly had been interviewed for a job by Google. Within the interview he was given this question: Suppose you have a folder with two files: a and b. Within that folder you execute: $ ls -a . > c What is the content of the file c? Well the solution is down there ↓, but you might want to take a guess :). Well, the content is: . .. a b c The reason for this is that the Shell executes the prompt commands in a separate process. For this purpose it uses fork() to create a child process and within the child process it prepares the environment for the ls command. The most crucial part to this preparation phase is the setup of the stdin, stdout and stderr file descriptors. The ls command is agnostic to the fact that it should output to the file c. It behaves the same way as it would when the > would be ommitted, meaning it would print directly to the terminal. So basically within the child process the file descriptor for c is created and duplicated onto stdout. ls prints to stdout, which now points to the file c. In summary: the file c must exist before invoking ls.