Split from - http://www.daniweb.com/forums/thread118867.html

int main()
{
    int i , parent_id , ans ;

    parent_id = getpid() ; 
   
    for ( i = 1 ; i <= 5 ; i++ )
    {

       if ( getpid() == parent_id )
       {

         ans = fork() ;
 
         wait() ;
       }

       if ( ans == 0 )
       {
  
         sleep(i) ;
  
         printf ( " \n I am a child my pid is %d " , getpid() ) ;

         exit(0) ;
       } 
     }

     printf ( " \n I am the father my pid is %d " , parent_id ) ;
   
     return 0 ;
}

but can you tell me which header files to inlcude for wait() and fork() system call.

>can you tell me which header files to inlcude for wait() and fork() system call.

1. wait() - <sys/wait.h>
2. fork() - <unistd.h>