Computing.Net > Forums > Unix > Processes and Pipelining Unix

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Processes and Pipelining Unix

Reply to Message Icon

Name: Trivialnight
Date: February 22, 2005 at 13:36:50 Pacific
OS: Solaris
CPU/Ram: Unknown
Comment:

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.


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



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


coping folder contents Different locaiton of com...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Processes and Pipelining Unix

Process and Memory Management www.computing.net/answers/unix/process-and-memory-management/3040.html

unix system process frees ports www.computing.net/answers/unix/unix-system-process-frees-ports/7592.html

Unix History www.computing.net/answers/unix/unix-history/1612.html