Mathematical-Reasoning
October 5, 2023ISO-OSI-layers
October 5, 2023Operating-Systems
Question 6 |
The following C program is executed on a Unix/Linux system:
#include <unistd.h> int main () { int i ; for (i=0; i<10; i++) if (i%2 == 0) fork ( ) ; return 0 ; }
The total number of child processes created is _____.
26 | |
33 | |
31 | |
28 |
Question 6 Explanation:
Fork( ) statement is executed when ‘i’ is even. Thus the above code is equivalent to
#include
int main( )
{
int i;
fork( );
fork( );
fork( );
fork( );
fork( );
}
n – fork statements will have 2n-1 child.
Hence, n = 5 ⇒ We have 31 child processes.
#include
int main( )
{
int i;
fork( );
fork( );
fork( );
fork( );
fork( );
}
n – fork statements will have 2n-1 child.
Hence, n = 5 ⇒ We have 31 child processes.
Correct Answer: C
Question 6 Explanation:
Fork( ) statement is executed when ‘i’ is even. Thus the above code is equivalent to
#include
int main( )
{
int i;
fork( );
fork( );
fork( );
fork( );
fork( );
}
n – fork statements will have 2n-1 child.
Hence, n = 5 ⇒ We have 31 child processes.
#include
int main( )
{
int i;
fork( );
fork( );
fork( );
fork( );
fork( );
}
n – fork statements will have 2n-1 child.
Hence, n = 5 ⇒ We have 31 child processes.
Subscribe
Login
0 Comments