Hy!
I must wrote some code with fork() command. The thing is that i have a while statement which count till 10.
I must wrote a program that one child has only one parent. So one parent has only one child and one child has only one parent. Can you please help me with these code.
int main()
{
int N,i,pid = 0;
scanf("%d",&N);
while(i <= N)
{
pid = fork();
if (pid == 0)
{
printf("child proc %d = %x\n", i, getpid());
wait(NULL);
}
if(pid != 0)
{
printf("Parent proc %d = %x\n", i, getppid());
exit(0);
}
i++;
}
}
What i'm doing wrong. Please help!