Operating Systems 2019F: Assignment 2

From Soma-notes
Jump to navigation Jump to search

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