Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 4 : 4

Advertisement

Detailed Solution

सही उत्तर 4 है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

Consider the C program: int main(){ if(fork() && fork()) fork(); return 0; } Including the original process, how many total processes exist after execution? / C प्रोग्राम पर विचार करें: int main(){ if(fork() && fork()) fork(); return 0; } मूल प्रोसेस सहित, निष्पादन के बाद कुल कितने प्रोसेस मौजूद होंगे?

1.
3
2.
5
3.
6
4.
4

Correct Answer: 4

The first fork creates child C1. In the parent the first fork returns nonzero (true), so the second fork runs and creates C2; it also returns nonzero in the parent, so the third fork runs and creates C3. In C1 the first fork returns 0, so && short-circuits and nothing more runs. In C2 the second fork returns 0, so the third fork is skipped. Total: original + C1 + C2 + C3 = 4. / पहला fork चाइल्ड C1 बनाता है। पैरेंट में पहला fork अशून्य (true) लौटाता है, अतः दूसरा fork चलता है और C2 बनाता है; वह भी पैरेंट में अशून्य लौटाता है, अतः तीसरा fork चलता है और C3 बनाता है। C1 में पहला fork 0 लौटाता है, अतः && शॉर्ट-सर्किट हो जाता है। C2 में दूसरा fork 0 लौटाता है, अतः तीसरा fork छूट जाता है। कुल: मूल + C1 + C2 + C3 = 4।

Downloaded from PrepSnap (prepsnap.in)