Midterm 2 Solutions

Topics: Virtual memory, IP address, Memory management Pages: 5 (1903 words) Published: May 11, 2012
CSCI 4061: Introduction to Operating Systems Fall 2008 Mid-Term Exam II Sample Solution


General Instructions: • Write your name and student ID clearly above. • You have 1 hour and 15 minutes to write the exam. No extra time will be given. • There are 4 questions in the exam, all with subparts. The questions combine for a maximum of 100 points. • You must write your answers clearly in the space provided for each question. You might use the backside of each page, as well as any additional sheets as required. If you are using additional space, you must clearly label the question no. that you are answering. Any loose sheets must have your name and student ID written clearly. • The exam is open book/open notes, however, no exchange of materials is allowed. You must use your own notes/book. • Electronic devices (laptops, notebooks, PDAs, cell phones, etc.) are strictly prohibited. • Read each question carefully before answering. • Good luck with the exam!

For Grading Use Only

1 2 3 4 TOTAL

1. Consider a 32-bit machine with 128 MB of physical memory, that uses virtual memory and demand paging for memory management. If the page size is 4 KB, answer the following questions. (Note: For ease of calculation, you can assume 1K=1000, 1M=1000K, etc.) (a) (3 pts) How many physical frames are there in the system? Ans: 128M = 32K 4K (b) (3 pts) What is the maximum number of pages that a process can have in its virtual address space? Ans: The amount of virtual address space addressable by each process = 232 = 4GB. Therefore, maximum number of pages = 4G = 1M 4K (c) (12 pts) Suppose the page table for a process P contains the following entries. Page No. 3 2 1 0 Frame No. 1 3 4 7

Specify what physical address does each of the following virtual addresses maps to? Show your calculations here. i. 3456 Ans: Note that a virtual address can be represented in terms of its page number and offset within the page as follows: Virtual address = Page no.* Page size + offset Thus, given a virtual address, it can be converted into its page number and offset as follows: Page number = Address div (Page size) Offset = Address mod (Page size) Here, div and mod correspond to the quotient and remainder from the division. Thus, for address 3456, the page number is 3456 div 4K = 0, and the offset is 3456 mod 4K = 3456. To get the physical address, first the page number should be converted to the corresponding frame no. from the page table. In this case, the frame no. for page 0 is 7. Then, the physical address = Frame no. * Page size + offset. Here, this would be 7*4K+3456 = 31456. ii. 13456 Ans: Page number = 13456/4K = 3 Offset = 13456 mod 4K = 1456. Physical frame corresponding to Page 3 = 1. Physical address = 1*4K+1456 = 5456.

2. (a) (4 pts) Threads from the same process share the global data and the heap. Give one advantage and one disadvantage of this sharing. Ans: Advantage: Sharing the global data and the heap makes it very efficient for threads to communicate and to share data with each other. Disadvantage: Sharing data in this manner can lead to race conditions and possible data corruption without proper synchronization. (b) (4 pts) What is the reason for threads from the same process to have separate stacks? Give one possible drawback for the fact that all these stacks reside in the same address space. Ans: Each thread has its own stack to keep track of its own control flow for the execution path it is following. Giving each thread its own stack allows different threads to be performing different activities within a process at the same time, and helps increase parallelism. Possible drawback: The amount of stack space available to each thread is constrained by the number of threads that can be executing at the same time. Also, since these stacks are in the same address space, a thread can access the stack of another thread, and there could be stack overflows caused by bugs, creating security and memory corruption problems.

Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Fluids Midterm Exam 2 Solutions Essay
  • Essay about ACCT 346 Midterm Exam Solution
  • Midterm 2 with Solutions Econ311 Essay
  • ITI1100 Midterm 13 Solution 2 Essay
  • Essay on Midterm Exam Solution
  • Prev Midterm 2 Essay
  • Essay on Microeconomics Midterm #2
  • HIST 4A Midterm 2 Essay

Become a StudyMode Member

Sign Up - It's Free