Question: Given the c code below what is printed to the after invoking the program what is printed to standard output,what is in fileB.txt , and

Given the c code below what is printed to the after invoking the program what is printed to standard output,what is in fileB.txt, and what is in fileA.txt. All syscalls succeed
The program is invoked like the following:
$ cat fileA.txt
File text a
$ cat fileB.txt
File text b
$./a.out
$ echo hello world
Program:
char space[100];
int B = open("fileB.txt", O_WRONLY | O_CREAT | O_APPEND, 0666)
int A = open("fileA.txt", O_RDONLY);
printf("Hi!
");
dup2(B, STDOUT_FILENO);
printf("Good?
")
dup2(A, STDIN_FILENO);
for (;;){
ssize_t b_read = read(STDIN_FILENO, space, sizeof(space)); if (b_read ==0)
return 0;
ssize_t b_write = b_read; while (b_write >0)
b_write -= write(STDOUT_FILENO,
space + b_read-b_write, b_write);
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!