Question: Problem 0 . Suppose a file contains 2 0 0 bytes of data. A program successfully opens it for both reading and writing ( i

Problem 0. Suppose a file contains 200 bytes of data. A program successfully opens it for both
reading and writing (i.e., passing the mode O_READWR to open()), and gets back a file descriptor
number fd.
a. The program calls read(fd,buf,70) where buf is at least 70 bytes long. It does something
with the data read from the file, and then repeats the call. Both calls return the exact amount
requested. Then it then calls read(fd,buf,70) a third time. What value will it return?
(Assume no other program has the file open.)
b. Next the program calls write(fd,otherbuffer,40), and the call returns 40. Then it calls
read(fd,buf,40). What will the return value from that call be?
c. Suppose the programmer needs to read back the last 100 bytes of the file (including the ones
just written). What parameters should it invoke lseek() with so that its next read will return
the last 100 bytes of the file

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 Programming Questions!