Operating System Interview Questions and Answers
Question - 21 : - What is a semaphore?
Answer - 21 : - A semaphore is a hardware or a software tag variable whose value indicates the status of a common resource.
Its purpose is to lock the common resource being used. A process which needs the resource will check the semaphore to determine the status of the resource followed by the decision for proceeding.
In multitasking operating systems, the activities are synchronized by using the semaphore techniques
Question - 22 : - What kind of operations are possible on a semaphore?
Answer - 22 : - Two kind of operations are possible on a semaphore - 'wait' and 'signal'.
Question - 23 : - What is context switching?
Answer - 23 : - Context is associated with each process encompassing all the information describing the current execution state of the process
When the OS saves the context of program that is currently running and restores the context of the next ready to run process, it is called as context switching.
It is important for multitasking OS.
Question - 24 : - Tell us something about Mutex.
Answer - 24 : - Mutex - ‘Mutual Exclusion Lock’ is a lock which protects access to shared data resource.
Threads can create and initialize a mutex to be used later.
Before entering a critical region the mutex is locked. It is unlocked after exiting the critical region. If any thread tries to lock the mutex during this time, it can't do so.
Question - 25 : - What is a critical section?
Answer - 25 : - It is a section of code which can be executed only by one process at a time.
Question - 26 : - What is synchronization? What are the different synchronization mechanisms?
Answer - 26 : - Synchronization means controlling access to a resource that is available to two or more threads or process. Different synchronization mechanisms are:
- Mutex
- Semaphores
- Monitors
- Condition variables
- Critical regions
- Read/ Write locks
Question - 27 : - What is the basic difference between pre-emptive and non-pre-emptive scheduling.
Answer - 27 : - Pre-emptive scheduling allows interruption of a process while it is executing and taking the CPU to another process while non-pre-emptive scheduling ensures that a process keeps the CPU under control until it has completed execution.
Question - 28 : - Is non-pre-emptive scheduling frequently used in a computer? Why?
Answer - 28 : - No, it is rarely used for the reasons mentioned below:
- It can not ensure that each user gets a share of CPU regularly.
- The idle time with this increases reducing the efficiency and overall performance of the system.
- It allows program to run indefinitely which means that other processes have to wait for very long.
Question - 29 : - What are condition variable.
Answer - 29 : - These are synchronization objects which help threads wait for particular conditions to occur.
Without condition variable, the thread has to continuously check the condition which is very costly on the resources.
Condition variable allows the thread to sleep and wait for the condition variable to give it a signal
Question - 30 : - What are read-write locks?
Answer - 30 : - Read - write locks provide simultaneous read access to many threads while the write access stays with one thread at a time. They are especially useful in protecting the data that is not frequently written but read simultaneously by many threads.
- They are slower than mutexes.