CS FundamentalsHardGATE CS
What values are printed (in any order)? (Every fork() succeeds.)
What values are printed (in any order)? (Every fork() succeeds.)
int main() {
int x = 0;
for (int i = 0; i < 2; i++) {
if (fork() == 0) x += 1;
else x += 10;
}
printf("%d ", x);
}- A. 2, 11, 11, 20
- B. 2, 11, 20
- C. 1, 10, 11, 20
- D. 0, 1, 10, 11
Correct answer: A. 2, 11, 11, 20
Each process makes two decisions (child: +1, parent: +10). The four processes take the four combinations: parent-parent 20, parent-child 11, child-parent 11, child-child 2.
More Operating Systems questions
- A 32-bit system uses 2-level paging (10 + 10 + 12 bits, 4-byte PTEs, so every table is one 4 KB page). A process touches one byte in each…
- Disk with 100 cylinders (0–99); head at 50 moving up. Requests arrive in two batches: first 30, 70, 90; when the head reaches 70, new…
- A system has 3 identical printers. Processes P1, P2, P3 hold 1 printer each and each needs exactly 2 to finish; requests are made one at a…
- A program alternately computes for 20 ms and does disk I/O for 80 ms. With 4 such independent programs and the 1 − pⁿ model, what CPU…
- In a system with paging, a process's logical address space is 64 pages of 1 KB and physical memory is 32 frames. How many bits are in the…
- An 8 MB file uses linked indexed allocation: each 4 KB index block holds 1024 four-byte pointers, of which the last is reserved as the…