Sei sulla pagina 1di 6

Question 1 (General) (a) Describe three general methods for passing parameters to the operating system when making

a system call. Ans: Three general methods are used to pass parameters to the operating system are: a. Pass the parameters in registers b. Store parameter in a block c. Push parameter onto the stack by the program and pop off the stack by the operating system. (b) Modern operating systems are interrupt driven. Explain this statement. Ans: An interrupt is an asynchronous signal from hardware indicating the need for attention or a synchronous event in software indicating the need for a change in execution. A hardware interrupt causes the processor to save its state of execution via a context switch, and begin execution of an interrupt handler. Software interrupts are usually implemented as instructions in the instruction set, which cause a context switch to an interrupt handler similarly to a hardware interrupt. Interrupts are a commonly used technique for computer multitasking, especially in real-time computing. Such a system is said to be interrupt-driven. (c) What is dual-mode operation? Name and describe the features of the two modes. How does dual mode function as a rudimentary form of security? Ans: Dual mode of operation is the distinction between execution of user mode and kernel mode (supervisor mode, system mode, and privileged mode). user mode and kernel mode (also called supervisor mode, system mode, or privileged mode). A bit, called the mode bit, is added to the hardware of the computer to indicate the current mode: kernel (0) or user (1). Dual mode of operation provides us with more protection to the operating system. For example, if a kernel instruction is executed under user mode, the hardware does not execute it, although identifies it as an illegal execution and traps it to the operating system. (d) Define the essential properties of following operating systems I) real Time II) Interactive III) Hand Held Ans: i) Real time: A real-time operating system (RTOS) is intended to serve real-time application requests. It must be able to process data as it comes in, typically without buffering delays. ii) Interactive: The user interacts directly with the operating system to supply commands and data as the application program executes and the user receives the results of processing immediately. iii) Handheld: It operates on a smartphone, tablet, PDA, or other digital mobile devices Question 2 (Processes and Threads) (a) The main program of the Nachos has been modified to execute a new function called StartThread. Int main (int argc, char **argv) { int argCount; DEBUG('t', Entering Main) ; (void) initialize (argc,argv);

StartThread(); currentThread->Finish(); return 0; } The function StartThread runs the function MyFun, which takes an integer argument. StartThread is defined below. Void StartThread() { Thread *t1 = new Thread(MyThread); t1->fork(MyFun, 10); currentThread->Yield(); } Describe in detail the steps that will be executed, starting with the call to fork in StartThread, and ending with procedure call that transfer control to function MyFun. In other words write a trace of the major statements executed in order to start MyFun running. In particular calls to methods of thread and scheduler classes should be noted; you can ignore statements that enable or disable interrupts. Relevant Nachos code can be found in the Appendix of this exam paper. Ans: When a StartThread calls Fork, control is passed through the normal means to the operating system which then executes the Sys Fork function. This function is responsible for allocating the address space of the MyFun thread, copying the contents of the parents memory into the child, and setting the parent pointer. When the thread-specific structures are allocated, the system then calls the thread Fork function (shown below): pid = t->Fork((void(*)(size_t))Do_Fork, (size_t)(dummy)); (b) What is the effect of forking a process in Unix? Make sure to explain what occurs to all process involved. Give an example in which the procedure fork is used in order to start a separate process. Ans: A new process is created by the fork system call. The new process consists of a copy of the address space of the original process. This mechanism allows the parent process to communicate easily with its child process. Virtual memory can allow pages to be shared during process creation with the forkO system call, thus speeding up process creation. (c) Explain the purpose of ready list in Nachos. What causes a thread to be placed on the ready list? What causes the thread to be removed from the ready list? Ans: The processes that are residing in main memory and are ready and waiting to execute are kept on a list called the ready queue. A new process is initially put into ready queue until it is selected for execution. The process could be removed forcibly from the CPU, as a result of an interrupt, and be put back in the ready queue. If the process gets the CPU time for execution it comes out of ready queue. (d) Process change their states ready, wait (or blocked), and running. What are the possible causes for the following state transitions. I) from running to wait II) from wait to ready

III) from ready to running IV) from running to ready Ans: possible cause for process state transitions: 2. I/O event or event wait 3. I/O or event completion 4. Scheduler dispatch 5. Interrupt Question 3 (synchronization) (a) Consider a banking system that has two function: deposit (amount) and withdraw(amount). These two functions are passed the amount to be deposited or withdrawn from a bank account. Assume a shared bank account exists between a husband and wife and concurrently husband calls the withdraw() function and wife calls the deposit() function. Describe how a race condition is possible and what might be done to prevent the race condition from occurring. Ans: Suppose the account has $100 and husband calls withdraw($50) and wife deposit($75). But due to race condition one of the transaction is not reflected and it may led to $175 or $50 in bank account. (b) Show that, if the semWait() and semSignal()semaphore operations are not executed atomically then a semaphore could guarantee a mutual exclusion. Ans: A wait operation atomically decrements the value associated with a semaphore. If two wait operations are executed on a semaphore when its value is 1, if the two operations are not performed atomically, then it is possible that both operations might proceed to decrement the semaphore value thereby violating mutual exclusion. (c) Why are special techniques required to synchronize the action taking place in different threads in an operating system? Give an example. Ans: Thread synchronization can be achieved by using Pthread APIs. The Pthreads API provides mutex locks, condition variables, and read-write locks for thread synchronization. A mutex lock is used to protect critical sections of codethat is, a thread acquires the lock before entering a critical section and releases it upon exiting the critical section. (d) Describe the difference between Hoare style condition variables and Mesa style condition variables. Ans: Mesa-style condition variables define wake() to wake up another thread and place woken thread on the ready queue. It is the responsibility of the woken thread to reacquire the lock (this acquire is taken care of in sleep(). By contrast, Hoare-style condition variables define wake() to wake up another thread, give it the lock, and place directly on the CPU (i.e. woken thread runs immediately). Question 4 (Memory) (a) Consider a system that uses a pure demand paging I) when a process starts execution, how would characterize the page fault rate? Justify your answer. II) Once a working set of processes is loaded into memory, how would you characterize the page fault rate? Justify your answer. Your answer must include an explanation of the term working set. Ans: answer:

i) When a process first starts execution, the page fault rate would be 100% because there are no pages in memory to begin with so the process must fault each time until every page that it needs is in memory. ii) Once the working set for a process is loaded into memory, the page fault rate would be 0%. This is because every page that it needs is in memory. (b) Compare the memory organization schemes of contiguous memory allocation, pure segmentation and pure paging with respect to following issues. I) External fragmentation II) Internal fragmentation Ans: Contiguous memory allocation] Contiguous memory allocation scheme suffers from external fragmentation as address spaces are allocated contiguously and holes develop as old processes dies and new processes are initiated. This scheme doesnt have internal fragmentation. Pure segmentation Pure segmentation also suffers from external fragmentation as a segment of a process is laid out contiguously in physical memory and fragmentation would occur as segments of dead processes are replaced by segments of new processes. This scheme doesnt have internal fragmentation. Pure paging Pure paging does not suffer from external fragmentation. But instead suffers from internal fragmentation. Processes are allocated in page granularity and if a page is not completely utilized, it results in internal fragmentation and a corresponding wastage of space. (c) Consider the following segment table. Segment base Length 0 219 600 1 2300 14 2 90 100 3 1327 580 4 1952 96 What are the physical address for the following logical address? i)0,567 ii)1,17 iii)2,31 iv)3,571 v)4,110 Ans: Physical addresses are: i) 567+219 = 786 ii) illegal reference, trap to operating system iii) 31+90= 121 iv) 571+1327=1898 v) illegal reference, trap to operating system (d) Describe how to use a stack to implement the LRU page-replacement algorithm. Consider the following page reference sequence. 1,2,3,4,2,1,3,2,1,2

Assuming that there are three page frames, show the state of the stack after each page reference, and indicate which reference produced a page fault. Ans: Frame 1 2 3 4 2 1 3 2 1 2 1 1 1 1 4* 4 4 3* 3 3 3 2 2 2 2 2 2 2 2 2 2 3 3 3 3 1* 1 1 1 1 Star (*) denotes page fault. In total three segmentation fault will happen. Question 5 (File Systems) (a) What are the advantages and disadvantages of providing mandatory file locks instead of advisory file locks? Ans: Advantages of mandatory file locking: a) Easy to implement Disadvantages of mandatory file locking: a) Entire file unavailable to other users/programs and becomes required for other programs to wait for certain time until the file is free (b) What is the difference between hard links and soft links in Unix. Unix supports links to file that cross mount points (that is the link refers to a file stored on a different volume) but only soft links not hard links. Why? Ans: Hard Links 1. Hard Links have same inodes number. 2. Links have actual file contents 3. You cannot create a hard link for a directory. Soft Links 1. Soft Links have different inodes numbers. 2. Soft Link contains the path for original file and not the contents. 3. A soft link can link to a directory. Hard links in unix has same inode number. So, a same inode number will make a confusing reference to the mount point. So, its not allowed in unix. (c) Some system provide file sharing by maintaining a single copy of a file; other system maintains several copies; one for each of the user sharing the file. List the differences in the users view of each approach. Ans: With a single copy, several concurrent updates to a file may result in user obtaining incorrect information, and the file being left in an incorrect state. With multiple copies, there is storage waste and the various copies may not be consistent with respect to each other. (d) Consider the system that supports the strategies of contiguous, linked and indexed allocation for files. What properties of a file should be used in deciding which strategy is best for that file (that is, what are each methods advantages). Ans: Advantages: a. Contiguous allocation: It is the fastest allocation scheme if no changes are to be made. Also

easiest for random access files. b. Linked allocation: No external fragmentation happens in this scheme. File can grow without complications. c. Indexed allocation: Supports direct access of files without external fragmentation.

Potrebbero piacerti anche