Operating Systems 2019F: Assignment 2: Difference between revisions
Line 33: | Line 33: | ||
for i in `seq 1 10`; rm dest; do time ./3000redact-rw line source dest; done | for i in `seq 1 10`; rm dest; do 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. |
Revision as of 19:52, 5 October 2019
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 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.
When asked to modify source files, you may want to give your code in "diff -c" format.
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] 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?
- [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?
- [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 3000test.c so it reports the three times associated with an inode, atime, mtime, and ctime (in a human-readable time format). What do these times mean and when are they updated on files on your system?
- [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 register is changed to allocate local variables? Explain briefly with an example.
- [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).
- [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.)
- [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.
- [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`; rm dest; do 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.