CS FundamentalsModerateTCS NQT · Infosys pattern
How many times is "hi" printed? (Assume every fork() succeeds.)
How many times is "hi" printed? (Assume every fork() succeeds.)
int main() {
for (int i = 0; i < 3; i++)
fork();
printf("hi\n");
return 0;
}- A. 8
- B. 7
- C. 6
- D. 3
Correct answer: A. 8
Each fork doubles the number of processes, so after 3 forks there are 2³ = 8 processes and each prints once. 7 is the number of child processes created, not the number of printers.
More Operating Systems questions
- A system has 32-bit logical addresses, a page size of 4 KB and 4-byte page-table entries. What is the size of a single-level page table…
- Four processes share a pool of identical resource instances, and each process needs at most 3 instances to finish. What is the minimum…
- A counting semaphore S is initialised to 5. Then 7 wait (P) operations and 3 signal (V) operations are performed on it in some order. What…
- A process of size 13,000 bytes is loaded with paging, page size 4,096 bytes. How much internal fragmentation is there in its last page?
- Processes: P1 (arrival 0, burst 7), P2 (arrival 2, burst 4), P3 (arrival 4, burst 1), P4 (arrival 5, burst 4) (ms). Using non-preemptive…
- A child process has terminated, but its parent has not yet called wait() to read its exit status. The child is now a: