Difference between revisions of "Operating Systems 2021F: Assignment 4"

From Soma-notes
Jump to navigation Jump to search
Line 53: Line 53:
</li>
</li>
<li>[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?</li>
<li>[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?</li>
<li>[3] What is the relationship between <tt>nonempty_mutex</tt> and <tt>queue_nonfull</tt> in 3000pc-rendezvous-timeout.c?  Specifically, what is each for, and why are both necessary?
<li>[3] What is the relationship between <tt>nonempty_mutex</tt> and <tt>queue_nonempty</tt> in 3000pc-rendezvous-timeout.c?  Specifically, what is each for, and why are both necessary?
</ol>
</ol>

Revision as of 00:31, 6 December 2021

Please submit the answers to the following questions via Brightspace by December 9, 2021 at 10:00 AM. There are 20 points in 8 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 UNIX text file! Submissions in an invalid format will get an automatic grade of zero. To validate the format of your submission, use validate-submissions-a4.js as follows:

# if you haven't installed nodejs yet (or install nodejs locally on Windows/MacOS)
sudo apt install nodejs

nodejs validate-submissions-a4.js randomstudent-comp3000-assign4.txt

(If you get an error about it being a DOS/Windows text file, your file is the wrong kind of text file.)

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);
              }
      
    • Add the following include lines to the top (for the call to open):
             #include <sys/types.h>
             #include <sys/stat.h>
             #include <fcntl.h>
      

    Note that 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?
  8. [3] What is the relationship between nonempty_mutex and queue_nonempty in 3000pc-rendezvous-timeout.c? Specifically, what is each for, and why are both necessary?