LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   about pipes (https://www.linuxquestions.org/questions/programming-9/about-pipes-373342/)

kpachopoulos 10-15-2005 11:59 AM

about pipes
 
Hi,
lets say i create a pipe with:
-----------------
ints fds[2];
pipe(fds);
-----------------
Is fds[0] the STANDARD read end of the pipe and pipe[1[ the STANDARD write end? I have read this, but i have also read these in the same program:
-----------------
fdopen(pipe[0], "r");
fdopen(pipe[1],"w");
----------------
Does that mean that pipe[0] for read and pipe[1] for write are not standard and they are just conventions?

aluser 10-15-2005 12:37 PM

fds[0] is open for reading and fds[1] is open for writing after you call pipe(). This means that you can call read() and write() on them, respectively.

fdopen() returns a FILE* on which you can fwrite(), fread(), or fprintf(). The mode you pass to fdopen needs to be compatible with the file descriptor you pass it; in this case you must pass fds[0] for reading and fds[1] for writing.

The FILE type is an abstraction over integer file descriptors. The functions which operate on it (fprintf and so on) do some buffering in your program to make it a little faster.


All times are GMT -5. The time now is 05:18 AM.