top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How many process will be created ??

+5 votes
342 views
int main() 
{ 
    if(fork() && fork()) 
    { 
        fork(); 
    } 
    if(fork() || fork()) 
    { 
        fork(); 
    } 

    printf(“Hello world”); 
    return 0; 
} 
posted Nov 4, 2013 by Mona Sharma

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

If the first fork return 0 then second fork in the first "if" condition wont get executed.
So the number of processes will be depends on return value of fork call present in both "if" conditions.

answer Nov 4, 2013 by sivanraj
Similar Questions
0 votes
while(true)
{
  sleep(1); /* sleep for 1 second */
  if(getpid()%2 == 0)
  {
     fork();
  }
}

How many no.of processes are created by the end of 12th second, if
time starts from 0th second? Process id's start from 0.

+4 votes

Lets assume I have a system with RAM of 1GB. and virtual memory is 500MB. That brings to 1.5GB i.e. 1500 MBytes.

I have read somewhere that when I process is created stack of 8MB is associated to that process. So, assuming that any of the process is not allocating any dynamic memory or anything, then does it mean that, Maximum number of process that i can create is 1500/8 and i.e. 187 Process.

Please clarify my understanding,

+4 votes

Say there is a function fun(p1, p2, p3, p4);
Is Context switching possible after pushing p1, p2 and before pushing p3 and p4 in stack ?

...