Operating System Interview Questions and Answers
Question - 41 : - Explain thread.
Answer - 41 : - - It is an independent flow of control within a process.
- It consists of a context and a sequence of instructions for execution.
Question - 42 : - What are the advantage of using threads?
Answer - 42 : - The main advantages of using threads are:
a.) No special communication mechanism is required.
b.) Readability and simplicity of program structure increases with threads.
c.) System becomes more efficient with less requirement of system resources.
Question - 43 : - What are the disadvantages of using threads?
Answer - 43 : - The main disadvantages of using threads are:
- Threads can not be re-used as they exist within a single process.
- They corrupt the address space of their process.
- They need synchronization for concurrent read-write access to memory.
Question - 44 : - What is a compiler?
Answer - 44 : - A compiler is a program that takes a source code as an input and converts it into an object code. During the compilation process the source code goes through lexical analysis, parsing and intermediate code generation which is then optimized to give final output as an object code.
Question - 45 : - What is a library?
Answer - 45 : - It is a file which contains object code for subroutines and data to be used by the other program.
Question - 46 : - What are the advantages of distributed system?
Answer - 46 : - Advantages of distributed system are:
- Resources get shared
- Load gets shared
- Reliability is improved
- Provide a support for inter-process communication
Question - 47 : - What are the different types of scheduling algorithms?
Answer - 47 : - The scheduling algorithms decide which processes in the ready queue are to be allocated to the CPU for execution. Scheduling algorithms can be broadly classified on the basis of:
- Preemptive algorithms
- Round Robin Scheduling
- Shortest Job First Scheduling (can be both)
- Priority Scheduling (can be both)
- Non-preemptive algorithms
- First Come First Served Scheduling
Non-Preemptive algorithms: In this type of scheduling once a CPU has been allocated to a process it would not release the CPU till a request for termination or switching to waiting state occurs.
Preemptive algorithms: In this type of scheduling a process maybe interrupted during execution and the CPU maybe allocated to another process.
Question - 48 : - Why is round robin algorithm considered better than first come first served algorithm?
Answer - 48 : - The first come first served algorithm is the simplest scheduling algorithm known. The processes are assigned to the CPU on the basis of their arrival time in the ready queue. Since, it is non-preemptive once a process is assigned to the CPU, it will run till completion. Since a process takes the CPU till it is executed it is not very good in providing good response times. It can make other important processes wait un-necessarily.
On the other hand, the round robin algorithm works on the concept of time slice or also known as quantum. In this algorithm, every process is given a predefined amount of time to complete the process. In case, a process is not completed in its predefined time then it is assigned to the next process waiting in queue. In this way, a continuous execution of processes is maintained which would not have been possible in case of FCFS algorithm
Question - 49 : - Explain how a copying garbage collector works. How can it be implemented using semispaces?
Answer - 49 : - The copying garbage collector basically works by going through live objects and copying them into a specific region in the memory. This collector traces through all the live objects one by one. This entire process is performed in a single pass. Any object that is not copied in memory is garbage.
The copying garbage collector can be implemented using semispaces by splitting the heap into two halves. Each half is a contiguous memory region. All the allocations are made from a single half of the heap only. When the specified heap is half full, the collector is immediately invoked and it copies the live objects into the other half of the heap. In this way, the first half of the heap then only contains garbage and eventually is overwritten in the next pass.
Question - 50 : - How does reference counting manage memory allocated objects? When can it fail to reclaim objects?
Answer - 50 : - Reference counting augments every object with a count of the number of times an object has been referenced. This count is incremented every time a reference to that object is made. Also every time a reference is destroyed the reference is decremented. This process is repeated till the reference count becomes zero. Once the reference count of an object reaches zero the object can be reclaimed. In this way, reference counting systems can perform automatic memory management by keeping a count in every object. Any object that does not have a reference count can be considered to be dead and that memory can be reclaimed.
The reference counting method can fail to reclaim objects in case of cyclic references. There are no concrete ways to avoid this problem and it is always suggested to create an architecture that does not use a circular reference.