Well I did a little more testing on it and the problem seems to be that the parent process is not breaking out of the for loop like it is suppose to and not executing findfib() until the last process.
Code:
void doall(int id, int np)
{
printf("ID: %d\n",id);
}
void mkpipeln(int *id, int np)
{ int fd[2]; pid_t child;
for(*id = 1; *id < np; (*id)++){
pipe(fd);
child = fork();
if(child > 0){
dup2(fd[1],1);
if((close(fd[0])<0)||(close(fd[1])<0)) die("close-1 failed");
break;}
else{
printf("Parent: %d\n",(int)getppid());
printf("Child: %d\n",(int)getpid());
dup2(fd[0],0);
if((close(fd[0])<0)||(close(fd[1])<0 )) die("close-1 failed");
}
}
}
Output for 7 processes if it helps at all:
Quote:
Parent: 6282
Child: 6283
Parent: 6283
Child: 6284
Parent: 6284
Child: 6285
Parent: 6285
Child: 6286
Parent: 6286
Child: 6287
Parent: 6287
Child: 6288
ID: 7
|
-tn