GATE 2003
107 questions
MCQ 1071-mark 107
Questions 91–95 of 107
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.
Which of the following will ensure that the output string never contains a substring of the form or , where n is odd?
Process P:
while (1) {
W:
print '0';
print '0';
X:
}
Process Q:
while (1) {
Y:
print '1';
print '1';
Z:
} Synchronization statements can be inserted only at points W, X, Y and Z.Which of the following will ensure that the output string never contains a substring of the form or , where n is odd?
Answer: (C)
P prints 0 twice in a row and Q prints 1 twice in a row. If the two pairs never mix, the output is a string of whole blocks 00 and 11. Then every run of 1s between two 0s is made of whole 11 blocks, so its length n is even. The same holds for runs of 0s between two 1s. So the forbidden substrings and with odd n cannot appear.
To keep the pairs from mixing, the two critical sections (P's two prints, Q's two prints) must exclude each other. One semaphore S, starting at 1, with P(S) before each pair and V(S) after it, does this. That is option C.
Why the others fail (each lets the prints mix, for example 0 1 0, which has n = 1):
A: P uses S and Q uses T. These are different semaphores, so neither process ever waits for the other. P prints one 0, Q prints 1, P prints 0.
B: S and T both start at 1, so P(S) in P and P(T) in Q both succeed at once. Both processes enter together and their prints can interleave.
D: P does V(S) at W, which never blocks, so P prints without waiting. Q's P(S) at Y finds S = 1 and passes. So Q can print between P's two zeros.
Answer: (C)
To keep the pairs from mixing, the two critical sections (P's two prints, Q's two prints) must exclude each other. One semaphore S, starting at 1, with P(S) before each pair and V(S) after it, does this. That is option C.
Why the others fail (each lets the prints mix, for example 0 1 0, which has n = 1):
A: P uses S and Q uses T. These are different semaphores, so neither process ever waits for the other. P prints one 0, Q prints 1, P prints 0.
B: S and T both start at 1, so P(S) in P and P(T) in Q both succeed at once. Both processes enter together and their prints can interleave.
D: P does V(S) at W, which never blocks, so P prints without waiting. Q's P(S) at Y finds S = 1 and passes. So Q can print between P's two zeros.
Answer: (C)
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.
Which of the following will always lead to an output staring with '001100110011' ?
Process P:
while (1) {
W:
print '0';
print '0';
X:
}
Process Q:
while (1) {
Y:
print '1';
print '1';
Z:
} Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will always lead to an output staring with '001100110011' ?
Answer: (B)
For the output
P:
Trace: Q is blocked at
(A) uses
(C) has at the start, so Q can pass
(D) also keeps
Answer: (B)
001100110011..., P must print its two 0s, then Q its two 1s, and so on, taking turns with P first. Use for P's turn and for Q's turn.P:
P(S) at W, V(T) at X. Q: P(T) at Y, V(S) at Z. Start with and .Trace: Q is blocked at
P(T) because , so only P can start. P passes P(S) (), prints 00, and V(T) sets . P cannot go again, since . Q passes P(T), prints 11, and V(S) sets . Now P can go again. So the output is 00 11 00 11 and so on.(A) uses
S only in P and T only in Q. The two processes do not wait for each other, so the 0s and 1s can mix in any order.(C) has at the start, so Q can pass
P(T) and print 11 first. The output may start with 1.(D) also keeps
S in P and T in Q. Q waits on and nobody ever signals T before Q's own V(T), so Q never prints and the output is only 0s.Answer: (B)
The following are the starting and ending times of activities A,B,C,D,E,F,G and
H respectively in chronological order: . Here, denotes the starting time and
denotes the ending time of activity X. W need
to schedule the activities in a set of rooms available to us. An activity can be
scheduled in a room only if the room is reserved for the activity for its entire
duration. What is the minimum number of rooms required?
Answer: (B)
Two activities need different rooms if their times overlap. Draw a node for each activity, and join two nodes if the activities overlap. The minimum number of rooms is the chromatic number of this graph, and the graph is an interval graph, so it equals the largest number of activities running at the same time.
Just after the activities running are B, D, E and F, since none of them has ended yet. They overlap pairwise, so they form a clique of 4 nodes (b, d, e, f) and need 4 different rooms. At no other time are more than 3 activities running.
4 rooms are enough: Room 1 gets B, G. Room 2 gets A, D, H. Room 3 gets C, E. Room 4 gets F. In each room the activities do not overlap (for example comes before , and before ).
Answer: (B)
Just after the activities running are B, D, E and F, since none of them has ended yet. They overlap pairwise, so they form a clique of 4 nodes (b, d, e, f) and need 4 different rooms. At no other time are more than 3 activities running.
4 rooms are enough: Room 1 gets B, G. Room 2 gets A, D, H. Room 3 gets C, E. Room 4 gets F. In each room the activities do not overlap (for example comes before , and before ).
Answer: (B)
A uni-processor computer system only has two processes, both of which alternate 10 ms CPU bursts with 90 ms I/O bursts. Both the processes were created at nearly the same time. The I/O of both processes can proceed in parallel. Which of the following scheduling strategies will result in the least CPU utilizations (over a long period of time) for this system ?
Answer: (D)
CPU utilization CPU burst time / total time of one cycle.
FCFS:
Time 0-10: process 1 runs
Time 10-20: process 2 runs
Process 1 started its I/O at 10 and is back at 100, so time 100-110: process 1 runs, and 110-120: process 2 runs
...
So in every 100 ms the CPU is used for 20 ms, and the utilization
SRTF:
The CPU bursts are equal, so it is the same as FCFS: 20%.
Static priority:
If process 1 has the higher priority, the schedule is the same as FCFS. If process 2 has it, the schedule is the same with the two processes swapped. So the utilization stays at 20%.
Round Robin (quantum 5 ms):
Time 0-5: process 1 runs
Time 5-10: process 2 runs
Time 10-15: process 1 runs its second 5 ms and finishes its burst, so its 90 ms I/O runs from 15 to 105
Time 15-20: process 2 finishes its burst, and its I/O runs from 20 to 110
Time 105-110: process 1 runs again
Time 110-115: process 2 runs
...
Because the two bursts are cut into two slices each, process 1 ends its burst at 15 and so is back only at 105. The cycle is 105 ms, with 20 ms of CPU use: utilization
19.05% is less than 20%, so round robin gives the least utilization.
(Round robin with a time quantum of 10 ms would have made the CPU utilization the same for all the schedules.)
Answer: (D)
FCFS:
Time 0-10: process 1 runs
Time 10-20: process 2 runs
Process 1 started its I/O at 10 and is back at 100, so time 100-110: process 1 runs, and 110-120: process 2 runs
...
So in every 100 ms the CPU is used for 20 ms, and the utilization
SRTF:
The CPU bursts are equal, so it is the same as FCFS: 20%.
Static priority:
If process 1 has the higher priority, the schedule is the same as FCFS. If process 2 has it, the schedule is the same with the two processes swapped. So the utilization stays at 20%.
Round Robin (quantum 5 ms):
Time 0-5: process 1 runs
Time 5-10: process 2 runs
Time 10-15: process 1 runs its second 5 ms and finishes its burst, so its 90 ms I/O runs from 15 to 105
Time 15-20: process 2 finishes its burst, and its I/O runs from 20 to 110
Time 105-110: process 1 runs again
Time 110-115: process 2 runs
...
Because the two bursts are cut into two slices each, process 1 ends its burst at 15 and so is back only at 105. The cycle is 105 ms, with 20 ms of CPU use: utilization
19.05% is less than 20%, so round robin gives the least utilization.
(Round robin with a time quantum of 10 ms would have made the CPU utilization the same for all the schedules.)
Answer: (D)
A processor uses 2-level page tables for virtual to physical address translation. Page tables for both levels are stored in the main memory. Virtual and physical addresses are both 32 bits wide. The memory is byte addressable. For virtual to physical address translation, the 10 most significant bits of the virtual address are used as index into the first level page table while the next 10 bits are used as index into the second level page table. The 12 least significant bits of the virtual address are used as offset within the page. Assume that the page table entries in both levels of page tables are 4 bytes wide. Further, the processor has a translation look-aside buffer (TLB), with a hit rate of 96%. The TLB caches recently used virtual page numbers and the corresponding physical page numbers. The processor also has a physically addressed cache with a hit rate of 90%. Main memory access time is 10 ns, cache access time is 1 ns, and TLB access time is also 1 ns.
Suppose a process has only the following pages in its virtual address space: two contiguous code pages starting at virtual address 0x00000000, two contiguous data pages starting at virtual address 0x00400000, and a stack page starting at virtual address 0xFFFFF000. The amount of memory required for storing the page tables of this process is:
Suppose a process has only the following pages in its virtual address space: two contiguous code pages starting at virtual address 0x00000000, two contiguous data pages starting at virtual address 0x00400000, and a stack page starting at virtual address 0xFFFFF000. The amount of memory required for storing the page tables of this process is:
Answer: (C)
Each table has entries of 4 bytes, so each table is 4 KB.
The first-level index is the top 10 bits of the address, the second-level index the next 10 bits.
Code pages at 0x00000000 and 0x00001000: first-level index 0 (second-level indices 0 and 1).
Data pages at 0x00400000 and 0x00401000: , so first-level index 1 (second-level indices 0 and 1).
Stack page at 0xFFFFF000: first-level index 1023 (second-level index 1023).
The three first-level entries 0, 1 and 1023 differ, so 3 second-level tables are needed.
Total = 1 first-level table + 3 second-level tables = KB.
Answer: (C)
The first-level index is the top 10 bits of the address, the second-level index the next 10 bits.
Code pages at 0x00000000 and 0x00001000: first-level index 0 (second-level indices 0 and 1).
Data pages at 0x00400000 and 0x00401000: , so first-level index 1 (second-level indices 0 and 1).
Stack page at 0xFFFFF000: first-level index 1023 (second-level index 1023).
The three first-level entries 0, 1 and 1023 differ, so 3 second-level tables are needed.
Total = 1 first-level table + 3 second-level tables = KB.
Answer: (C)