CS FundamentalsHardGATE CS
How many times are 'c' and 'p' printed in total? (Every fork() succeeds.)
How many times are 'c' and 'p' printed in total? (Every fork() succeeds.)
int main() {
for (int i = 0; i < 3; i++) {
if (fork() == 0) printf("c");
else printf("p");
}
}- A. 10 c and 3 p
- B. 7 c and 7 p
- C. 3 c and 3 p
- D. 14 c and 14 p
Correct answer: B. 7 c and 7 p
At iteration i there are 2^i processes, each forks once; the child prints c and the parent prints p. So each iteration prints 2^i c's and 2^i p's: total 1 + 2 + 4 = 7 of each.
More Operating Systems questions
- How many times is each letter printed? (Every fork() succeeds.) c int main() { if (fork() == 0) { if (fork() == 0) printf("A"); else…
- What is the sum of the values printed by all processes? (Every fork() succeeds.) c int main() { int n = 0; for (int i = 0; i < 3; i++) {…
- 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?