CS FundamentalsHardGATE CS
How many times is "x" printed? (Every fork() succeeds.)
How many times is "x" printed? (Every fork() succeeds.)
int main() {
if (fork() == 0) {
if (fork() == 0)
fork();
}
printf("x\n");
}- A. 8
- B. 3
- C. 5
- D. 4
Correct answer: D. 4
Original + child1; child1 forks child2; child2 forks child3. That is a chain of 4 processes, each printing once.
More Operating Systems questions
- How many times is "x" printed? (Every fork() succeeds.) c int main() { for (int i = 0; i < 2; i++) { fork(); fork(); } printf("xn"); }
- 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…