q2_fall05_sol

q2_fall05_sol - Department of Electrical Engineering and...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.828 Operating System Engineering: Fall 2005 Quiz II Solutions Average 84, median 83, standard deviation 10. I 6.828 FALL 2005, Quiz 2 Solutions Page 2 of 13 O/S Bugs 1. [10 points]: The correctness of JOS depends in part on interrupts not occurring while the kernel is executing. Suppose that by mistake your JOS kernel didnt turn off interrupts when entering the kernel. Explain a specific problem that would arise if a clock interrupt occurred while executing the code for a system call in the kernel. Answer: The interrupt will execute on the kernel stack, and will push its state below the system calls stack frames. trap() in the interrupt will overwrite the current environments envtf with a return point in the system call code in the kernel. There are two possible sequences of events now, both of which lead to errors. If the interrupt returns without calling schedyield() , it will return back into the system call. When the system call returns, it will use the same envtf , and will return into the middle of the kernel system call code rather than back to user space. If the interrupt calls schedyield() to switch to a new environment, it will return to the user space in the new environment. The old environments system call will never be finished: next time it runs, it will run in user space as if the system call had returned. 6.828 FALL 2005, Quiz 2 Solutions Page 3 of 13 II Shells The file script contains the following two lines: echo first echo 2nd You type the following command to a shell: $ sh < script > out 2. [5 points]: What should file out contain after this command? Answer: first 2nd 6.828 FALL 2005, Quiz 2 Solutions Page 4 of 13 The JOS library sets the PTESHARE bit in the page table entry of the page that contains each struct Fd . This bit causes spawn and fork to share Fd pages read/write with child environments, instead of copying them. Heres what struct Fd looks like, from inc/fd.h : struct Fd { int fd_dev_id; off_t fd_offset; int fd_omode; union { // File server files struct FdFile { int id; struct File file; } fd_file; } } 3. [10 points]: What would file out contain in the above example if the JOS library copied Fd pages in spawn and fork , instead of sharing them read/write? Explain your answer. Answer: In unmodified JOS, the page containing the struct Fd is shared between the parent, the children, and the file server. Thus the children see each others modifications to Fd.fdoffset when they write the file, so the second echo starts writing where the first left off. Similarly, the children share the Fd page with the server, so both children see the servers changes to the Fd.fdfile.file.fsize field when either child sends a setsize RPC to the server to increase the file size....
View Full Document

Page1 / 13

q2_fall05_sol - Department of Electrical Engineering and...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online