top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How many process get created??

0 votes
391 views
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.

posted Aug 14, 2014 by Prakash Singh

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

1 Answer

+2 votes

I think you can't predict no. of process are created by the end of 12th sec.

because of the pid, assume the very first time (i.e after 1 sec) you got getpid() as 0
than
if( will be ture) {
// then it will create a process, which pid may or may not be even value.
}
If the value is not even then the
if( false ) {
// and hence it won't do any more fork(). or vice verse.
}

answer Aug 14, 2014 by Arshad Khan
Similar Questions
+4 votes

So many times, we make foreground process to background process in linux system. How does it handle internally ?

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

    printf(“Hello world”); 
    return 0; 
} 
+2 votes

How a background process is treated by operating system ?

...