The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
"inappropriate ioctl for device" 421 service not available, remote server has closed connection ^m ascii eof autosys awk trim bash eval bash exec bash for loop bash subroutine boot: cannot open kernel/sparcv9/unix close_wait curses.h dead.letter find grep grep multiple lines grep or grep recursive grep unique inappropriate ioctl for device logrotate.conf lynx javascript mailx attachment make: fatal error: command failed for target `all-recursive' mget mtime perl array length ping port read awk output into multiple variables replace space by comma , perl script scp recursive segmentation fault(coredump) sftp batch sftp script snoop unix stale nfs file handle syn_sent tar exclude unix unix .profile unix com unix for loop unix forum unix forums unix interview questions unix memory usage unix mtime unix simulator unix.com while loop within while loop shell script

View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 02-22-2005
Trivialnight Trivialnight is offline
Registered User
 

Join Date: Feb 2005
Posts: 3
Pipelining Processes

I am doing a program that will calculate the 199th fibonacci number using pipelines and multiple processes for each calculation. I have figured everything out except why none of the processes before the last one never execute the findfib() function;

Our teacher gave us the pipeline code to redirect stdin and stdout, but even when i execute the example file he gave us with it. It still is just running the findfib function at the last process only, I would go ask him about it but today he doesn't have any office hours. All the right headers are there. I have written the code for calculate the numbers using strings and whatnot but this is the only thing that is holding me back from completing. It seems as though the child never equals the parent which makes it not go into the if parent parent.

Code:
int
main(int argc, char *argv[])
{
   int i,nproc;
   if(chkargs(argc,argv) == 0) exit(1);
   nproc = strtol(argv[1],0,0);
   mkpipeln(&i,nproc);
   findfib(i,nproc);
   exit(0);
}

void
mkpipeln(int *id, int np)
{  int fd[2]; pid_t child;
   for(*id = 1; *id < np; (*id)++) {
       if(pipe(fd) < 0) die("pipe-1 failed");
       if((child = fork()) < 0) die("fork failed");
       if(child > 0){

         if(dup2(fd[1],1) < 0) die("dup2-1 failed");
         if((close(fd[0]) < 0) || (close(fd[1]) < 0)) die("close-1 failed");
         break;
       }
       else{
         if(dup2(fd[0],0) < 0) die("dup2-2 failed");
         if((close(fd[0]) < 0) || (close(fd[1]) < 0)) die("close-2 failed");
       }
   }
   printf("id: %d\n", *id);
}

void
findfib(int id, int np)
{  printf("id: %d\n", id);
}
Now shouldn't it print out each ID in each process?

-tn
Reply With Quote
Forum Sponsor