Operating Systems 2021F: Assignment 4

From Soma-notes
Revision as of 05:17, 30 November 2021 by Soma (talk | contribs) (→‎Questions)

This assignment is still being developed.

Please submit the answers to the following questions via Brightspace by December 9, 2021 at 10:00 AM. There are 20 points in ?? questions.

Submit your answers as a plain text file following this template. Name your answer file "<username>-comp3000-assign4.txt" (where username is your MyCarletonOne username).

Your answers will be parsed by a script in order to help with grading so please preserve the format of the template. Make sure the file remains a plain text file! No other formats will be accepted.

Don't forget to include what outside resources you used to complete each of your answers, including other students, man pages, and web resources. You do not need to list help from the instructor, TA, or information found in the textbook.

Questions

  1. [2] System call code in the Linux kernel run in the context of a task. What is the variable name representing that task? What type is that variable?
  2. [2] When making a read call on /dev/ones, the ones_read() function is called. The read system call takes three arguments, but ones_read() takes four. Explain at a high level how each argument for ones_read() comes from the arguments passed to a read system call.
  3. [2] The ones_fops struct is declared in the ones module on lines 51-55 and referenced on line 69. What does ones_fops specify? Does it have any fields that aren't initialized? Explain briefly.
  4. [2] If we replace line 38 of the ones module with buf[i] = '1';, how does the behavior of the ones module change? Why?
  5. [4] How can we make the ones module act as if there are exactly 10,000 1's? Specifically, if we read /dev/ones from the beginning we should get 10,000 1's at which point the file ends. Note that this should work no matter the size of the buffer used for a read system call. (You may want to test using dd.)
  6. [3] Change 3000pc-fifo.c as follows:
    • Delete lines 192-196 (the lines that call pipe())
    • Replace lines 200-209 with the following:
              if (pid == 0)
              {
                      /* Producer */
                      pipefd[1] = open("the_pipe", O_WRONLY);
                      producer(count, pipefd[1], prod_interval);
              }
              else
              {
                      /* Consumer */
                      pipefd[0] = open("the_pipe", O_RDONLY);
                      consumer(count, pipefd[0], con_interval);
              }
      

    This code assumes that the_pipe exists and is writable.

    1. [1] How does this modified version behave if the_pipe is an empty regular file?
    2. [1] Does its behavior change if we run it multiple times (without emptying the_pipe)? How?
    3. [1] Can we create a file that will make the modified 3000pc-fifo behave like the original? Explain briefly.
  7. [2] If we replace the call to mmap() in 3000pc-rendezvous-timeout.c (lines 399-401) with a call to malloc(), how will the behavior of the program change? Why?