Operating System

Operating System Questions Answers GATE 2023

Share the Education

Operating System GATE Question Answers with Explanation.

Q1 – Which one or more of the following needs to be saved on a context switch from one thread (T1) of a process to another thread (T2) of the same process? (GATE 2023)
 
  1. Page table base register
  2. Stack pointer
  3. Program counter
  4. General purpose registers

Ans – (2, 3, 4)

Explanation – During a context switch from one thread (T1) to another thread (T2) within the same process, the following information needs to be saved:

  1. Program Counter (PC): This indicates the address of the next instruction to be executed.

  2. Stack Pointer (SP): Points to the top of the stack where local variables and function call information are stored.

  3. Register Values: The values stored in the processor registers need to be saved so that the state of the CPU is preserved. These registers include general-purpose registers, floating-point registers, and status registers.

Saving this information ensures that when the operating system switches between threads, the state of the executing thread is preserved, and execution can resume seamlessly from where it left off when the thread is scheduled to run again.

Q2 – Which one or more of the following options guarantees that a computer system will transition from user mode to kernel mode? (GATE 2023)
 
  1. Function Call
  2. malloc Call
  3. Page Fault
  4. System Call

Ans – (3, 4)

Explanation –

3. Page Fault: When a process attempts to access a memory page that is not currently loaded into physical memory, a page fault occurs. Handling page faults requires kernel intervention to load the necessary page from secondary storage into physical memory, which necessitates a transition from user mode to kernel mode.

4. System Call: System calls are requests made by a user-level process to the operating system kernel for performing privileged operations such as I/O operations, process control, and file management. When a process invokes a system call, it triggers a transition from user mode to kernel mode to execute the requested operation within the protected kernel space.

Q3 – Which one or more of the following CPU scheduling algorithms can potentially cause starvation? (GATE 2023)

 

  1. First-in First-Out
  2. Round Robin
  3. Priority Scheduling
  4. Shortest Job First

Ans – (1, 3, 4)

Explanation

The CPU scheduling algorithms that can potentially cause starvation are:

1. First-in First-Out (FIFO) – In FIFO scheduling, processes are executed in the order they arrive. If long-running processes continuously arrive, short processes may be delayed indefinitely, leading to starvation.

2. Priority Scheduling – Priority scheduling assigns priority levels to processes, and the scheduler selects the process with the highest priority for execution. If there are processes with high priority continuously arriving or if the scheduler always selects high-priority processes, lower-priority processes may starve, as they may never get a chance to execute.

3. Shortest Job First (SJF) – SJF scheduling selects the process with the smallest burst time next for execution. If there are constantly arriving long jobs, short jobs may starve as they continually get preempted by the arrival of longer jobs.

4. Round Robin (RR) – Round Robin scheduling, by design, does not cause starvation, as it allocates a fixed time quantum to each process. However, it may lead to poor performance for short processes if the time quantum is too large.

Q4 – Consider the two functions incr and decr shown below.
Q28 GATE 2023
There are 5 threads each invoking incr once, and 3 threads each invoking decr once, on the same shared variable X. The initial value of X is 10.

 

Suppose there are two implementations of the semaphores, as follows:
I-1: s is a binary semaphore initialized to 1.
I-2: s is a counting semaphore initialized to 2.
Let V1, V2 be the values of X at the end of execution of all the threads with implementations I-1, I-2, respectively.

 

Which one of the following choices corresponds to the minimum possible values of V1, V2, respectively? (GATE 2023)
  1. 15, 7
  2. 7, 7
  3. 12, 7
  4. 12, 8

Ans – (3)

Explanation

Let’s analyze the scenario using each semaphore implementation:

Implementation I-1: Binary Semaphore Initialized to 1
– With a binary semaphore initialized to 1, only one thread can access the critical section at a time.
– Since there are 5 threads invoking incr and 3 threads invoking decr, and incr and decr operations do not interfere with each other, they can execute concurrently.

Hence, the final value of X, V1, will be 10 (initial value) + 5 (incremented) – 3 (decremented) = 12.

Implementation I-2: Counting Semaphore Initialized to 2
– With a counting semaphore initialized to 2, up to two threads can access the critical section simultaneously.
– Again, since incr and decr operations do not interfere with each other, they can execute concurrently.
– Similar to the previous scenario, 5 threads invoking incr will increase X by 5, and 3 threads invoking decr will decrease X by 3.
– The maximum value of X after all incr threads run will be 10 + 5 = 15.

– The minimum value of X after all decr threads run will be 10 – 3 = 7.

So, the minimum possible values of V1 and V2 are 12 and 7, respectively, as you’ve provided. The correct answer is indeed 12, 7.