Operating Systems | Set 16

24 Sep, 2021
Following questions have been asked in GATE CS 2005 exam. 
1) Normally user programs are prevented from handling I/O directly by I/O instructions in them. For CPUs having explicit I/O instructions, such I/O protection is ensured by having the I/O instructions privileged. In a CPU with memory mapped I/O, there is no explicit I/O instruction. Which one of the following is true for a CPU with memory mapped I/O? (a) I/O protection is ensured by operating system routine(s) (b) I/O protection is ensured by a hardware trap (c) I/O protection is ensured during system configuration (d) I/O protection is not possible 
Answer (a) Memory mapped I/O means, accessing I/O via general memory access as opposed to specialized IO instructions. An example,  
  unsigned int volatile const *pMappedAddress const = (unsigned int *)0x100;
So, the programmer can directly access any memory location directly. To prevent such an access, the OS (kernel) will divide the address space into kernel space and user space. An user application can easily access user application. To access kernel space, we need system calls (traps). Thanks to Venki for providing the above explanation. 
2) What is the swap space in the disk used for? (a) Saving temporary html pages (b) Saving process data (c) Storing the super-block (d) Storing device drivers 
Answer (b) Swap space is typically used to store process data. See this for more details. 
3) Increasing the RAM of a computer typically improves performance because: (a) Virtual memory increases (b) Larger RAMs are faster (c) Fewer page faults occur (d) Fewer segmentation faults occur 
Answer (c) 
4) Suppose n processes, P1, .... Pn share m identical resource units, which can be reserved and released one at a time. The maximum resource requirement of process Pi is Si, where Si > 0. Which one of the following is a sufficient condition for ensuring that deadlock does not occur?  
Answer (c) In the extreme condition, all processes acquire Si-1 resources and need 1 more resource. So following condition must be true to make sure that deadlock never occurs.  
< m 
The above expression can be written as following.  
< (m + n) 
5) Consider the following code fragment:  
  if (fork() == 0)
  { a = a + 5; printf(“%d,%d\n”, a, &a); }
  else { a = a –5; printf(“%d, %d\n”, a, &a); } 
Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE? (a) u = x + 10 and v = y (b) u = x + 10 and v != y (c) u + 10 = x and v = y (d) u + 10 = x and v != y 
Answer (c) fork() returns 0 in child process and process ID of child process in parent process. In Child (x), a = a + 5 In Parent (u), a = a – 5; Therefore x = u + 10. The physical addresses of ‘a’ in parent and child must be different. But our program accesses virtual addresses (assuming we are running on an OS that uses virtual memory). The child process gets an exact copy of parent process and virtual address of ‘a’ doesn’t change in child process. Therefore, we get same addresses in both parent and child. See this run for example. Thanks to Smart Pointer for providing the above explanation. 
Please see GATE Corner for all previous year paper/solutions/explanations, syllabus, important dates, notes, etc. 
Please write comments if you find any of the answers/explanations incorrect, or you want to share more information about the topics discussed above. 
surinderdawra388
GATE-CS-2005
GATE CS
MCQ
Operating Systems
Operating Systems
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.