Unix and Pipes

trilobyte

Member
Feb 27, 2000
60
0
0
Having a little issue with pipes


Pipes need their own file descriptor array right? IE:

int fd[2];
pipe(fd);


...if I wanted 2 pipes....
int fd0[2], fd1[2];
pipe(fd0);
pipe(fd1);



...now my question. If I wanted to make 100 pipes, is there a way to write a loop that will create 100 different file-descritor arrays and 100 different pipes (in C)? A program I'm writing requires multiple pipes (one per process) to be all linked together, and the pipes must be created before the fork. Hence, my question.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
I haven't touched C in a long time and when I did I sucked, so this is just a crapshot :)

int pipes[100];
int n;

for(n=0; n<100; n++) {
int pipes[n][2];
pipe(pipes[n]);
}

I'm probably way off though :p
 

trilobyte

Member
Feb 27, 2000
60
0
0
Yeah, but how can I use that double array when closing the file descriptors?

like:

close(pipes[1][0]);

gives me a "cannot dereference non-pointer type" when I try to compile.