COMP1521 18s1 COMP1521 18s1 Final Exam Comp Sys Fundamentals
[Instructions] [Documentation]
[Q1] [Q2] [Q3] [Q4] [Q5] [Q6] [Q7] [Q8] [Q9] [Q10]

Question 7 (4 marks)

Consider the following 1000-byte file:

A is located at byte offset 0; B is located at byte offset 500; C is located at byte offset 999; D is located at byte offset 1000.

  1. Assume that the file is open for reading via a file descriptor in the fd variable and is located at position B before each call to lseek(). Indicate where the file will be positioned after each of the following calls to lseek():

    1.   /* at position B, then ... */ lseek(fd, 0L, SEEK_SET);

    2.   /* at position B, then ... */ lseek(fd, 0L, SEEK_CUR);

    3.   /* at position B, then ... */ lseek(fd, 500L, SEEK_SET);

    4.   /* at position B, then ... */ lseek(fd, 500L, SEEK_CUR);

  2. How large would the file be after each of the following sequences of statements:

    1.   fd = open("myFile", O_RDONLY); close(fd);

    2.   fd = open("myFile", O_WRONLY|O_APPEND); close(fd);

    3.   fd = open("myFile", O_RDWR|O_APPEND); close(fd);

    4.   fd = open("myFile", O_RDWR|O_TRUNC|O_CREAT); close(fd);

Type your answers to this question into the appropriate place in the q7.txt file, and submit it using the command:

submit q7

This will make a copy of the q7.txt file as your answer for this question. You can run the submit command as many times as you like, but only the most recent submission will be marked.