Consider the following code segment where program is a valid executable file:
1 2 3 4 5 6 7 8 9 10 11 12
if ( fork() == 0 ) {
close ( 1 );
close ( 2 );
if ( open ( "test.txt", O_WRONLY) == -1 )
exit ( 1 );
if ( open ( "test.txt", O_WRONLY) == -1 )
exit ( 1 );
execl ( "/bin/program", "program", 0 );
exit ( 1 );
}
Which of the following is true?
A. File descriptor 1 is used for standard input.
B. File descriptor 2 is used for standard output.
C. Both 1) and 2) are true.
D. In the above code, if program writes an error message (via the file descriptor 2), the message will overwrite the data of standard output that had already been written.
E. In the above code, file descriptors 1 and 2 refer to the different files.
I was thinking the answer was C but I'm unsure. I know it can't be E unless I'm wrong?