## Semaphores

Question 1 |

At a particular time of computation, the value of a counting semaphore is 10. Then 12 P operations and “x” V operations were performed on this semaphore. If the final value of semaphore is 7, x will be :

8 | |

9 | |

10 | |

11 |

Question 1 Explanation:

Initial value of counting semaphore is 10. And when a process enters the critical section it decreases the value of counting semaphore using P operation and when a process leaves the critical section it increases the value of counting semaphore using V operation.
So, here 12P (subtraction) and x(addition) operation are given. And after performing P(subtraction) and V(addition) the value of counting semaphore is 7.

7 = 10 -12 + x

x = 9

7 = 10 -12 + x

x = 9

Question 2 |

Two atomic operations permissible on Semaphores are __________ and __________.

wait, stop | |

wait, hold | |

hold, signal | |

wait, signal |

Question 2 Explanation:

A semaphore is a variable or abstract data type used to control access to a common resource by multiple processes in a concurrent system such as a multitasking operating system. Two atomic operations are

1. wait: If the value of semaphore variable is not negative, decrement it by 1. If the semaphore variable is now negative, the process executing wait is blocked (i.e., added to the semaphore's queue) until the value is greater or equal to 1. Otherwise, the process continues execution, having used a unit of the resource.

2. signal: Increments the value of semaphore variable by 1. After the increment, if the pre-increment value was negative (meaning there are processes waiting for a resource), it transfers a blocked process from the semaphore's waiting queue to the ready queue.

1. wait: If the value of semaphore variable is not negative, decrement it by 1. If the semaphore variable is now negative, the process executing wait is blocked (i.e., added to the semaphore's queue) until the value is greater or equal to 1. Otherwise, the process continues execution, having used a unit of the resource.

2. signal: Increments the value of semaphore variable by 1. After the increment, if the pre-increment value was negative (meaning there are processes waiting for a resource), it transfers a blocked process from the semaphore's waiting queue to the ready queue.

Question 3 |

At a particular time of computation, the value of a counting semaphore is 10. Then 12 P operations and “x” V operations were performed on this semaphore. If the final value of semaphore is 7, x will be :

8 | |

9 | |

10 | |

11 |

Question 3 Explanation:

Initial value of counting semaphore is 10. And when a process enters the critical section it decreases the value of counting semaphore using P operation and when a process leaves the critical section it increases the value of counting semaphore using V operation.

So here 12P (subtraction) and x(addition) operation are given. And after performing P(subtraction) and V(addition) the value of counting semaphore is 7.

7 = 10-12+x

x=9

So here 12P (subtraction) and x(addition) operation are given. And after performing P(subtraction) and V(addition) the value of counting semaphore is 7.

7 = 10-12+x

x=9

Question 4 |

In order to allow only one process to enter its critical section, binary semaphore are initialized to

0 | |

1 | |

2 | |

3 |

Question 4 Explanation:

→ In order to allow only one process to enter its critical section, binary semaphore are initialized to 1.

→ It will change its state after enters into critical section. It will be 0.

→ It will change its state after enters into critical section. It will be 0.

Question 5 |

A semaphore count of negative n means (s = – n) that the queue contains ________
waiting processes.

n + 1 | |

n | |

n – 1 | |

0 |

Question 5 Explanation:

A semaphore count of negative ‘n’ means (s=-n) that the queue contains ‘n’ waiting processes.

There are 5 questions to complete.