Friday 20 November 2015

IBPS IT SO-Operating system-Semaphores – 2

Semaphores – 2

1) What will happen if a non-recursive mutex is locked more than once ?
a) Starvation
b) Deadlock
c) Aging
d) Signaling
Answer: b
Explanation: If a thread which had already locked a mutex, tries to lock the mutex again, it will enter into the waiting list of that mutex, which results in deadlock. It is because no other thread can unlock the mutex.
2) A semaphore :
a) is a binary mutex
b) must be accessed from only one process
c) can be accessed from multiple processes
d) None of these
Answer: c
Explanation: None.
3) The two kinds of semaphores are : (choose two)
a) mutex
b) binary
c) counting
d) decimal
Answer: b and c
Explanation: None.
4) A mutex :
a) is a binary mutex
b) must be accessed from only one process
c) can be accessed from multiple processes
d) None of these
Answer: b
Explanation: None.
5) At a particular time of computation the value of a counting semaphore is 7.Then 20 P operations and 15 V operations were completed on this semaphore.The resulting value of the semaphore is : (GATE 1987)
a) 42
b) 2
c) 7
d) 12
Answer: b
Explanation: P represents Wait and V represents Signal. P operation will decrease the value by 1 everytime and V operation will increase the value by 1 everytime.
6) A binary semaphore is a semaphore with integer values : (choose two)
a) 1
b) -1
c) 0
d) 0.5
Answer: a and c
Explanation: None.
7) The following pair of processes share a common variable X :
Process A
int Y;
A1: Y = X*2;
A2: X = Y;
Process B
int Z;
B1: Z = X+1;
B2: X = Z;
X is set to 5 before either process begins execution. As usual, statements within a process are executed sequentially, but statements in process A may execute in any order with respect to statements in process B.
i) How many different values of X are possible after both processes finish executing ?
a) two
b) three
c) four
d) eight
Answer: c
Explanation: Here are the possible ways in which statements from A and B can be interleaved.
A1 A2 B1 B2: X = 11
A1 B1 A2 B2: X = 6
A1 B1 B2 A2: X = 10
B1 A1 B2 A2: X = 10
B1 A1 A2 B2: X = 6
B1 B2 A1 A2: X = 12
ii) Suppose the programs are modified as follows to use a shared binary semaphore T :
Process A
int Y;
A1: Y = X*2;
A2: X = Y;
signal(T);

Process B
int Z;
B1: wait(T);
B2: Z = X+1;
X = Z;
T is set to 0 before either process begins execution and, as before, X is set to 5.
Now, how many different values of X are possible after both processes finish executing ?
a) one
b) two
c) three
d) four
Answer: a
Explanation:The semaphore T ensures that all the statements from A finish execution before B begins. So now there is only one way in which statements from A and B can be interleaved:
A1 A2 B1 B2: X = 11.
8) Semaphores are mostly used to implement :
a) System calls
b) IPC mechanisms
c) System protection
d) None of these
Answer: b
Explanation: None.
9) Spinlocks are intended to provide __________ only.
a) Mutual Exclusion
b) Bounded Waiting
c) Aging
d) Progress
Answer: b
Explanation: None.

No comments:

Post a Comment