GATE 2012
82 questions
MCQ 821-mark 39 · 2-mark 43
Questions 46–50 of 82
Fetch_And_Add(X,i) is an atomic Read-Modify-Write instruction that reads the value of memory location X, increments it by the value i, and returns the old value of X. It is used in the pseudocode shown below to implement a busy-wait lock. L is an unsigned integer shared variable initialized to 0. The value of 0 corresponds to lock being available, while any non-zero value corresponds to the lock being not available.
AcquireLock(L){
while (Fetch_And_Add(L,1))
L = 1;
}
ReleaseLock(L){
L = 0;
} This implementationAnswer: (B)
Say P1 holds the lock, so L = 1. P2 runs Fetch_And_Add and gets 1 back, so L becomes 2. Before P2 runs "L = 1", P1 releases the lock and L = 0. After that, P2 sets L = 1.
Now no process holds the lock, but L = 1. So every process keeps spinning forever.
Answer: fails as L can take on a non-zero value when the lock is actually available
Now no process holds the lock, but L = 1. So every process keeps spinning forever.
Answer: fails as L can take on a non-zero value when the lock is actually available
Consider the 3 processes, P1, P2 and P3 shown in the table.
The completion order of the 3 processes under the policies FCFS and RR2 (round robin scheduling with CPU quantum of 2 time units) are
The completion order of the 3 processes under the policies FCFS and RR2 (round robin scheduling with CPU quantum of 2 time units) are
Answer: (C)
FCFS: The run order is P1 from 0-5, P2 from 5-12, then P3 from 12-16. Completion order: P1, P2, P3
RR2: The run order is P1 0-2, P2 2-4, P1 4-6, P3 6-8, P2 8-10, P1 10-11 (done), P3 11-13 (done), P2 13-16 (done). Completion order: P1, P3, P2
Answer: FCFS: P1, P2, P3; RR2: P1, P3, P2
RR2: The run order is P1 0-2, P2 2-4, P1 4-6, P3 6-8, P2 8-10, P1 10-11 (done), P3 11-13 (done), P2 13-16 (done). Completion order: P1, P3, P2
Answer: FCFS: P1, P2, P3; RR2: P1, P3, P2
Consider the virtual page reference string
1, 2, 3, 2, 4, 1, 3, 2, 4, 1
on a demand paged virtual memory system running on a computer system that has main memory size of 3 page frames which are initially empty. Let LRU, FIFO and OPTIMAL denote the number of page faults under the corresponding page replacement policy. Then
1, 2, 3, 2, 4, 1, 3, 2, 4, 1
on a demand paged virtual memory system running on a computer system that has main memory size of 3 page frames which are initially empty. Let LRU, FIFO and OPTIMAL denote the number of page faults under the corresponding page replacement policy. Then
Answer: (B)
The reference string is 1, 2, 3, 2, 4, 1, 3, 2, 4, 1 and there are 3 frames.
OPTIMAL (replace the page whose next use is farthest):
1, 2, 3 fault: {1, 2, 3}
2 hit
4 faults. Next uses are 1 (soon), 3 (soon) and 2 (latest), so replace 2: {1, 3, 4}
1, 3 hit
2 faults. 3 is never used again, so replace 3: {1, 4, 2}
4, 1 hit
Faults = 5
FIFO (queue, oldest first):
1, 2, 3 fault: 1, 2, 3
2 hit
4 faults, replaces 1: 2, 3, 4
1 faults, replaces 2: 3, 4, 1
3 hit
2 faults, replaces 3: 4, 1, 2
4, 1 hit
Faults = 6
LRU (least recently used first):
1, 2, 3 fault: 1, 2, 3
2 hit: 1, 3, 2
4 faults, replaces 1: 3, 2, 4
1 faults, replaces 3: 2, 4, 1
3 faults, replaces 2: 4, 1, 3
2 faults, replaces 4: 1, 3, 2
4 faults, replaces 1: 3, 2, 4
1 faults, replaces 3: 2, 4, 1
Faults = 9
So OPTIMAL (5) FIFO (6) LRU (9).
Answer: (B)
OPTIMAL (replace the page whose next use is farthest):
1, 2, 3 fault: {1, 2, 3}
2 hit
4 faults. Next uses are 1 (soon), 3 (soon) and 2 (latest), so replace 2: {1, 3, 4}
1, 3 hit
2 faults. 3 is never used again, so replace 3: {1, 4, 2}
4, 1 hit
Faults = 5
FIFO (queue, oldest first):
1, 2, 3 fault: 1, 2, 3
2 hit
4 faults, replaces 1: 2, 3, 4
1 faults, replaces 2: 3, 4, 1
3 hit
2 faults, replaces 3: 4, 1, 2
4, 1 hit
Faults = 6
LRU (least recently used first):
1, 2, 3 fault: 1, 2, 3
2 hit: 1, 3, 2
4 faults, replaces 1: 3, 2, 4
1 faults, replaces 3: 2, 4, 1
3 faults, replaces 2: 4, 1, 3
2 faults, replaces 4: 1, 3, 2
4 faults, replaces 1: 3, 2, 4
1 faults, replaces 3: 2, 4, 1
Faults = 9
So OPTIMAL (5) FIFO (6) LRU (9).
Answer: (B)
A file system with 300 GByte disk uses a file descriptor with 8 direct block addresses, 1 indirect block address and 1 doubly indirect block address. The size of each disk block is 128 Bytes and the size of each disk block address is 8 Bytes. The maximum possible file size in this file system is
Answer: (B)
One block can hold 128 / 8 = 16 addresses.
Most blocks a file can have = 8 (direct) + 16 (single indirect) + 16 16 (double indirect) = 280
Largest file size = 280 128 B = 35840 B = 35 KB
Answer: 35 KBytes
Most blocks a file can have = 8 (direct) + 16 (single indirect) + 16 16 (double indirect) = 280
Largest file size = 280 128 B = 35840 B = 35 KB
Answer: 35 KBytes
Given the basic ER and relational models, which of the following is INCORRECT?
Answer: (C)
The ER model allows an attribute to be multi-valued or composite. A relational table (1NF) allows only one atomic value or NULL for each attribute in a row.
Answer: In a row of a relational table, an attribute can have more than one value
Answer: In a row of a relational table, an attribute can have more than one value