Tuesday, March 1, 2016

Operating System Sample Paper 1




Part 1. Mark True or False for each of the following questions. (40 points)
eg) Operating systems execute user programs and make solving user problems easier.  True


1. Solid state disks are considered non­volatile storage and much faster than magnetic disks.

True

2. Shared memory is a more appropriate IPC mechanism than message passing for distributed systems.
False

3. Named pipes continue to exist in the system after the creating process has terminated.

True

4. Dual­mode consisting of user mode and kernel mode allows OS to increase CPU utilization in a system
True
5. Stack section of process in memory contains function parameters, return addresses, local variables
True

6. Long term schedulers strive for good mix of CPU­bound processes and IO­bound processes.

True

7. Processes switch from waiting state to running state on the completion of I/O or event.

True--- false

8. A program that runs in parallel using multiple threads makes testing and debugging easier.

False

9. Process Control Block (PCB) contains program code.

False

10. According to Amdahl's Law, the speedup with four cores is twice the speedup with two cores.

True may be


Part 2 (11­14). Please answer to the following questions. (40 points)



11. Suppose a program is 60% parallel and 40% serial in terms of execution time. If we modify this program so that it runs on multiple cores using multiple threads, we can get a speedup. If original single­threaded program took 10 seconds, how much time would the new multi­threaded program take ideally when there are 4 cores? Explain. (10 points)



















12. Thread Cancellation means terminating a thread before it has finished. There are two approaches to cancel a thread. Explain how they work and what kinds of issues they have.
(a) Asynchronous cancellation (5 points)












(b) Deferred cancellation (5 points)



13. Suppose there are two processes that are accessing the same account as below. (10 points)



14. Busy waiting, also known as spinlock, wastes CPU cycles that may be used by other processes productively. But it has an advantage in that no context switch is required. Explain when and why busy waiting is preferred in relation to the duration of critical section and number of CPU cores. (10 points)



Part 3 (15­16). Check out the following program and answer to each question. (30 points)


#define HISTORY_SIZE 5
#define BUFSIZE 100


float balance_history[HISTORY_SIZE];
int hindex = 0;
float balance = 75;


int increment(int idx, int size){
return (idx+1) % size;
}


void withdraw(float amount){
if (balance >= amount){
balance = balance ­ amount;
balance_history[hindex] = balance;
hindex = increment(hindex, HISTORY_SIZE);
}
}

int main()
{
pid_t   pid;   int i;


pid = fork();
printf("initial balance = %f\n",balance);
if(pid == 0){
for(i=0;i<10;i++) {
withdraw(10);
}
printf("child: balance = %f\n",balance);
/* balance history display for debugging for(i=0;i<HISTORY_SIZE;i++)
printf("child: balance[%d] = %f\n", i, balance_history[i]);
*/
}
if(pid > 0){
wait(NULL);
printf("parent: balance = %f\n",balance);
}
return 0;
}


15. What output will be displayed on the screen? Note that transactions take effect only when there is enough balance to withdraw the given amount from. (10 points)










16. Note that there are two lines of code surrounded by a block comment /* … */ above.
/* balance history display for debugging for(i=0;i<HISTORY_SIZE;i++)
printf("child: balance[%d] = %f\n", i, balance_history[i]);
*/
if we remove the comment and let it run, what output will be added to the screen by this code? (10 points)













17. Define a function ‘decrement()’ that takes an circular index, buffer size and returns its decrement as described in the following comment of the code. (10 points)
/*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
eg) decrement(2,5) returns 1 decrement(1,5) returns 0 decrement(0,5) returns 4 decrement(0,10) returns 9 decrement(0,20) returns 19
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*/
int decrement(int idx, int size){


...



}

2 comments:

  1. where are the soltions for Operating System Sample Paper 1 and Operating System Sample Paper 2. i am not able to find them.

    ReplyDelete
  2. can you post answers

    ReplyDelete