This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1The most common technique used for protecting a critical section in Linux is:
Option B
In Linux, a critical section is a part of the code that accesses shared resources, such as variables, files, or hardware, that must not be used by more than one process or thread at a time. To prevent data corruption or race conditions, Linux uses synchronization mechanisms to protect these critical sections. The most common technique used in the Linux kernel for this purpose is the spinlock.
A spinlock is a lightweight lock used in Linux to protect a critical section. It makes a process “spin” in a loop until it can enter the section, ensuring that only one process accesses the shared resource at a time without using heavy context switching.
Q: 2Which of the following statement is true about Semaphore?
I. It can be Implemented using software.
II. It can be Implemented using hardware.
Option C
A Semaphore is a synchronization tool used in operating systems to control access to shared resources in a multiprogramming or multitasking environment. It helps prevent problems such as race conditions, where multiple processes try to access the same resource simultaneously.
A semaphore works like a signaling mechanism between processes or threads. It maintains an integer value that is modified using two special operations:
Semaphores are mainly used for:
There are two main types of semaphores:
| Type of Semaphore | Description |
|---|---|
| Binary Semaphore | Has only 0 or 1 value and works like a lock. |
| Counting Semaphore | Can have multiple values and manages multiple resources. |
A Semaphore can be implemented using both software and hardware methods. Software Implementation uses operating system algorithms, while Hardware Implementation uses special atomic instructions such as Test-and-Set or Compare-and-Swap.
For example, if only one printer is available in a system, a semaphore ensures that only one process uses the printer at a time while other processes wait for their turn.
Q: 3A situation where several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular order in which access takes place is called
Option C
A Race Condition occurs when multiple processes or threads access and modify shared data concurrently, and the final outcome depends on the order in which the operations are executed. Since the execution order may vary, it can lead to inconsistent or unexpected results.
Q: 4Which type of semaphore can be used to provide mutual exclusion when mutex locks are not available?
Option B
Semaphore is a synchronization tool used to control access to shared resources in concurrent systems. There are two types of semaphores:
Mutex locks are specialized locks for mutual exclusion, but if they are not available, a binary semaphore can perform the same function.
Q: 5In order to allow only one process to enter its critical section, binary semaphore is initialised to
Option B
A binary semaphore is a synchronization mechanism that can take only two values, 0 or 1. It is used to control access to a critical section so that only one process can enter at a time.
When the semaphore is initialized to 1:
This ensures Mutual Exclusion, meaning only one process is in the critical section at any time. So, Binary semaphore acts like a lock (mutex (Mutual Exclusion)).
| Semaphore Type | Values | Use |
|---|---|---|
| Binary Semaphore. | 0 or 1 | Mutual exclusion. |
| Counting Semaphore. | 0 to n | Multiple resource access. |
Q: 6A counting semaphore was initialized to 8. Then 12 P (wait) operations and 7 V (signal) operations were completed on this semaphore. The resulting value of semaphore is—
Option C
You have reached the end of this topic. Continue learning with the next topic below.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.