Question: File I/O: The following problems refer to a file called numbers.txt, with contents the ASCII string 0123456789. You may assume calls to read() are atomic
File I/O: The following problems refer to a file called numbers.txt, with contents the ASCII string 0123456789. You may assume calls to read() are atomic with respect to each other. The following file, read and print one.h, is compiled with each of the following code files:
#ifndef READ_AND_PRINT_ONE #define READ_AND_PRINT_ONE #include #include static inline void read_and_print_one(int fd) { char c; read(fd, &c, 1); printf("%c", c); fflush(stdout); } #ENDIF
A. Consider the following code:
#include "read_and_print_one.h" #include #include int main() { int file1 = open("numbers.txt", O_RDONLY); int file2; int file3 = open("numbers.txt", O_RDONLY); file2 = dup2(file3, file2); read_and_print_one(file1); read_and_print_one(file2); read_and_print_one(file3); read_and_print_one(file2); read_and_print_one(file1); read_and_print_one(file3); return 0; }
List all possible outputs of the above code.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
