CS FundamentalsModerateGATE CS
How many times is "x" printed? (Every fork() succeeds.)
How many times is "x" printed? (Every fork() succeeds.)
int main() {
for (int i = 0; i < 2; i++) {
fork();
fork();
}
printf("x\n");
}- A. 4
- B. 8
- C. 16
- D. 32
Correct answer: C. 16
Four forks are executed by every process in sequence, each doubling the count: 2⁴ = 16.
More Operating Systems questions
- How many times is "x" printed? (Every fork() succeeds.) c int main() { if (fork() || fork()) fork(); printf("xn"); }
- Semaphores a = 1, b = 0. P: wait(a); print 1; signal(b); signal(b). Q: wait(b); print 2; signal(a). R: wait(b); print 3. Each runs once…
- Shared x = 1. T1 does x = x + 1; T2 and T3 each do x = x 2; (load, compute, store, no locks). How many distinct final values of x are…
- How many of these statements about threads are correct? 1. A thread that calls exit() terminates the whole process. 2. If one thread…
- A server uses a fixed pool of 8 worker threads, and each request does a blocking database call taking 90% of its time. Roughly how many…
- Which statement about user-mode and kernel-mode stacks is correct?