Operating Systems 2019F: Assignment 2: Difference between revisions

From Soma-notes
No edit summary
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''This assignment is not yet finalized.'''
Please submit the answers to the following questions via CULearn by 4 PM on Friday, October 11, 2019. There are 20 points in 10 questions.
 
Submit your answers as a gzipped tarball named "<username>-comp3000-assign2.tgz" (where username is your MyCarletonOne username). This tarball should expand to a directory with the same name (without .tgz), and in this directory should be the following files:
 
  <username>-comp3000-assign2-answers.txt
  3000test-times.c
  redact-mmap.c 
  redact-rw.c
  <any other programs you wrote to answer the assignment>
 
The first four lines of the answers file should be "COMP 3000 Assignment 2", your name, student number, and the date of submission. You may wish to format your answers in Markdown to improve their appearance.
 
You can create a tarball using command
 
  tar czf <tarfile> <source dir>


Please submit the answers to the following questions via CULearn by 4 PM on Friday, October 11, 2019. There are 20 points in 10 questions.
So if your username is "janedoe" you'd do the following:


Submit your answers as a single text file named "<username>-comp3000-assign2.txt" (where username is your MyCarletonOne username). The first four lines of this file should be "COMP 3000 Assignment 2", your name, student number, and the date of submission. You may wish to format your answers in Markdown to improve their appearance.
  tar czf janedoe-comp3000-assign2.tgz janedoe-comp3000-assign2


When asked to modify source files, you may want to give your code in "diff -c" format.
(You can extract the file by running tar xzf <tarball>)


No other formats will be accepted. Submitting in another format will likely result in your assignment not being graded and you receiving no marks for this assignment. In particular do not submit an MS Word or OpenOffice file as your answers document!
No other formats will be accepted. Submitting in another format will likely result in your assignment not being graded and you receiving no marks for this assignment. In particular do not submit an MS Word or OpenOffice file as your answers document!
Line 15: Line 29:
# [1] Assume you have a file "animal.c".  You type <tt>ln animal.c frog.c</tt>  in order to create file "frog.c".  If you rename "animal.c" to "animal-base.c", what happens when you try to edit "frog.c"?  Why?
# [1] Assume you have a file "animal.c".  You type <tt>ln animal.c frog.c</tt>  in order to create file "frog.c".  If you rename "animal.c" to "animal-base.c", what happens when you try to edit "frog.c"?  Why?
# [1] Assume you have a file "animal.c".  You type <tt>ln -s animal.c penguin.c</tt>  in order to create file "penguin.c".  If you rename "animal.c" to "animal-base.c", what happens when you try to edit "penguin.c"?  Why?
# [1] Assume you have a file "animal.c".  You type <tt>ln -s animal.c penguin.c</tt>  in order to create file "penguin.c".  If you rename "animal.c" to "animal-base.c", what happens when you try to edit "penguin.c"?  Why?
# [2] What dynamic symbols are defined in the object file for 3000shell.c (when compiled normally)? Where can you find the code or data referred to by these symbols?
# [2] What symbols are referenced but not defined/allocated in the object file for 3000shell.c (when compiled with -c)? Where (ultimately) is the code or data referred to by these symbols?
# [2] Modify [https://homeostasis.scs.carleton.ca/~soma/os-2017f/code/tut3/3000test.c 3000test.c] so it reports the three times associated with an inode, atime, mtime, and ctime.  What do these times mean and when are they updated on files on your system?
# [2] Modify [https://homeostasis.scs.carleton.ca/~soma/os-2017f/code/tut3/3000test.c 3000test.c] so it reports the three times associated with an inode, atime, mtime, and ctime (in a human-readable time format).  Call your new program 3000test-times.c.  What do these times mean and when are they updated on files on your system?
# [2] What x86-64 assembly instructions are used to put parameters on the call stack? How do you know?  Show relevant assembly code and corresponding C code.
# [2] How is the first argument passed to a function in x86-64 assembly? Give an example of this happening in assembly and the corresponding C code.
# [2] What x86-64 assembly instructions are used to allocate local variables?  How do you know?  Show relevant assembly code and corresponding C code.
# [2] What x86-64 register is changed to allocate local variables?  Explain briefly with an example.
# [2] Make a program <tt>redact-mmap.c</tt> that takes two arguments: a string s and a filename f.  <tt>redact</tt> should mmap f into its address space and then replace every occurance of s with X's (with the number of X's corresponding to the length of s).
# [2] Make a program <tt>redact-mmap.c</tt> that takes three arguments: a string r and filenames s and d.  <tt>redact</tt> should replace every occurrence of r with X's in file s (the number of X's corresponding to the length of r), writing the output to d.  Alternately, you can do the replacement in place (instead of writing to d, just change s).
# [2] Make a program <tt>redact-rw.c</tt> that does the same thing as <tt>redact-mmap.c</tt> except that it uses reads and writes (of 4096 bytes at a time) rather than mmap.
# [2] Make a program <tt>redact-rw.c</tt> that does the same thing as <tt>redact-mmap.c</tt> except that it uses reads and writes (of 4096 bytes at a time) rather than mmap. (You can ignore matches that cross block boundaries.)
# [3] Compare the performance of <tt>redact-mmap</tt> versus <tt>redact-rw</tt>.  Which is faster on large files?  Why do you think this is the case?  Try using the time command to benchmark your programs, making sure to do at least ten trials.
# [3] Compare the performance of <tt>redact-mmap</tt> versus <tt>redact-rw</tt>.  Which is faster on large files?  Why do you think this is the case?  Try using the time command to benchmark your programs, making sure to do at least ten trials.
# [3] What happens when process A mmap's file f and process B appends to file f.  Will process A see the additional data added to the file by B (if A does no other system calls)?  Design an experiment and document your results.
# [3] What happens when process A mmap's file f and process B appends to file f.  Will process A see the additional data added to the file by B (if A does no other system calls)?  Design an experiment and document your results.
==Hints==
If you want to create big file for redaction, try something like this:
  rm source; echo "This is a line of text" > source; for i in `seq 1 18`; do cat source >> t; cat t >> source; done; rm t
This will create a source file with 530M of text.  Note you can also use a for loop to run your benchmarks:
  for i in `seq 1 10`; do rm dest; time ./3000redact-rw line source dest; done
Note time by default outputs to standard error.  So, you can get all of your times by adding a "2> times.txt" to the end of the above.
==Solutions==
[https://homeostasis.scs.carleton.ca/~soma/os-2019f/solutions/assign2-sol.txt Assignment 2 solutions]

Latest revision as of 20:13, 11 October 2019

Please submit the answers to the following questions via CULearn by 4 PM on Friday, October 11, 2019. There are 20 points in 10 questions.

Submit your answers as a gzipped tarball named "<username>-comp3000-assign2.tgz" (where username is your MyCarletonOne username). This tarball should expand to a directory with the same name (without .tgz), and in this directory should be the following files:

 <username>-comp3000-assign2-answers.txt
 3000test-times.c
 redact-mmap.c  
 redact-rw.c
 <any other programs you wrote to answer the assignment>

The first four lines of the answers file should be "COMP 3000 Assignment 2", your name, student number, and the date of submission. You may wish to format your answers in Markdown to improve their appearance.

You can create a tarball using command

 tar czf <tarfile> <source dir>

So if your username is "janedoe" you'd do the following:

 tar czf janedoe-comp3000-assign2.tgz janedoe-comp3000-assign2

(You can extract the file by running tar xzf <tarball>)

No other formats will be accepted. Submitting in another format will likely result in your assignment not being graded and you receiving no marks for this assignment. In particular do not submit an MS Word or OpenOffice file as your answers document!

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. [1] Assume you have a file "animal.c". You type ln animal.c frog.c in order to create file "frog.c". If you rename "animal.c" to "animal-base.c", what happens when you try to edit "frog.c"? Why?
  2. [1] Assume you have a file "animal.c". You type ln -s animal.c penguin.c in order to create file "penguin.c". If you rename "animal.c" to "animal-base.c", what happens when you try to edit "penguin.c"? Why?
  3. [2] What symbols are referenced but not defined/allocated in the object file for 3000shell.c (when compiled with -c)? Where (ultimately) is the code or data referred to by these symbols?
  4. [2] Modify 3000test.c so it reports the three times associated with an inode, atime, mtime, and ctime (in a human-readable time format). Call your new program 3000test-times.c. What do these times mean and when are they updated on files on your system?
  5. [2] How is the first argument passed to a function in x86-64 assembly? Give an example of this happening in assembly and the corresponding C code.
  6. [2] What x86-64 register is changed to allocate local variables? Explain briefly with an example.
  7. [2] Make a program redact-mmap.c that takes three arguments: a string r and filenames s and d. redact should replace every occurrence of r with X's in file s (the number of X's corresponding to the length of r), writing the output to d. Alternately, you can do the replacement in place (instead of writing to d, just change s).
  8. [2] Make a program redact-rw.c that does the same thing as redact-mmap.c except that it uses reads and writes (of 4096 bytes at a time) rather than mmap. (You can ignore matches that cross block boundaries.)
  9. [3] Compare the performance of redact-mmap versus redact-rw. Which is faster on large files? Why do you think this is the case? Try using the time command to benchmark your programs, making sure to do at least ten trials.
  10. [3] What happens when process A mmap's file f and process B appends to file f. Will process A see the additional data added to the file by B (if A does no other system calls)? Design an experiment and document your results.

Hints

If you want to create big file for redaction, try something like this:

  rm source; echo "This is a line of text" > source; for i in `seq 1 18`; do cat source >> t; cat t >> source; done; rm t

This will create a source file with 530M of text. Note you can also use a for loop to run your benchmarks:

 for i in `seq 1 10`; do rm dest; time ./3000redact-rw line source dest; done

Note time by default outputs to standard error. So, you can get all of your times by adding a "2> times.txt" to the end of the above.

Solutions

Assignment 2 solutions