CS FundamentalsVery hardGATE CS
What is the sum of the values printed by all processes? (Every fork() succeeds.)
What is the sum of the values printed by all processes? (Every fork() succeeds.)
int main() {
int n = 0;
for (int i = 0; i < 3; i++) {
if (fork() > 0) n++;
else break;
}
printf("%d\n", n);
}- A. 6
- B. 4
- C. 12
- D. 9
Correct answer: A. 6
Only the original keeps looping (each child breaks immediately), so there are 4 processes: the original prints 3 and each child prints the n it inherited at the moment it was created (0, 1, 2). Sum = 6.
More Operating Systems questions
- Disk cylinders 0–199, head at 50 moving TOWARD 0. Requests: 176, 79, 34, 60, 92, 11, 41, 114. What is the total head movement under SCAN…
- Disk cylinders 0–199, head at 50. Requests: 176, 79, 34, 60, 92, 11, 41, 114. Under SSTF, in what order are the requests served?
- A disk rotates at 10,000 RPM with 600 sectors per track. Seek time = 3 ms average. A request reads 300 sectors that lie on one track…
- A page fault occurs on a store instruction. Which sequence is correct for a demand-paged OS when a free frame exists?
- Which hardware support is essential for demand paging to work with instructions that can fault midway (for example a block-move…
- Which statement about the dirty (modified) bit in a page-table entry is correct?