Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you answer the question provided and explain how that answer was provided. T

ID: 3586388 • Letter: C

Question

Can you answer the question provided and explain how that answer was provided. Thank you

4. [20 points] Unix I/O and file operations

a. [10 points] Suppose that the file “tmpdata.txt” contains “abcdefghijk”. If the

following code is executed correctly without generating any errors.

1: int fd;

2: char buf[6] = “12345”;

3: fd = open(“tmpdata.txt”, O_RDONLY);

4: fork( );

5: read(fd, buf, 2);

6: read(fd, buf+2, 2);

7: printf(“%d: %s ”, (long)getpid(), buf);

i). [5pt] Explain if the following two outputs are possible or not? Why/why not? Suppose parent's

pid is 7 while child's pid is 8.

7:a2bc5

8:a2b45

7:a2c45

8:b2de5

ii). [5pt] What could be the outputs if the lines 3 and 4 are exchanged? Write at least 3 possible

outputs. Suppose parent's pid is 7 while child's pid is 8.

Explanation / Answer

i) No following outputs are not possible.
   beacuse read is for 2 bytes so buf will have its first two bytes
   modified in any case. But the given outputs don't comply with
   that
   Probable outputs are abcd5 for parent and efgh5 for child

ii) If we exchange 3 and 4 the basic difference will be that child
    and parent reading of the file will become independent.
    So the most likely possible outputs (or may be the only output)
    will be:
    7:abcd5
    8:abcd5  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote