The following program demonstrates the use of the dup2 system call to execute the ls program and write its stdout to a file called dir.txt.