Discussion
The number of child processes are created using the following code :
int main()
{ fork(););
fork();
fork();
return 0;
}
Answer: C
The code creates 7 child processes.
Each fork() duplicates every process that executes it, so the number of processes doubles with each call. After three calls there are
\[ \begin{aligned} 2^{3} &= 8 \text{ processes} \\ &= 1 \text{ parent} + 7 \text{ children} \end{aligned} \]
The first line as printed has a stray ');' after the first call, which a compiler would reject; the question intends three successive fork() calls. 8 counts the original parent as well, and 5 and 6 do not arise from doubling.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development