Hi
My aim is to create 4 individual childs for a parent and the parent will wait until the 3rd child expires. For that I write the code like this but I am not getting the output correctly. If any one know the problem in code please reply.
[code=c]
main()
{
int i = 4;
for( i =0 ;i < 4 ;i++)
{
if(fork())
{
fflush(stdout);
printf("\nparen t : %d",getpid()) ;
}
else
{
fflush(stdout);
printf("\nchild : %d frm parent:%d",getp id(),getppid()) ;
sleep(5);
exit(0);
}
}
printf("parent waiting for third child");
wait(3);
printf("parent terminating");
}
[/code]
regards
satya
My aim is to create 4 individual childs for a parent and the parent will wait until the 3rd child expires. For that I write the code like this but I am not getting the output correctly. If any one know the problem in code please reply.
[code=c]
main()
{
int i = 4;
for( i =0 ;i < 4 ;i++)
{
if(fork())
{
fflush(stdout);
printf("\nparen t : %d",getpid()) ;
}
else
{
fflush(stdout);
printf("\nchild : %d frm parent:%d",getp id(),getppid()) ;
sleep(5);
exit(0);
}
}
printf("parent waiting for third child");
wait(3);
printf("parent terminating");
}
[/code]
regards
satya
Comment