LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-15-2005, 11:59 AM   #1
kpachopoulos
Member
 
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 705

Rep: Reputation: 30
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?
 
Old 10-15-2005, 12:37 PM   #2
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pipes in python? SciYro Programming 9 08-02-2006 09:35 AM
Question regarding pipes alltime Programming 3 04-15-2005 07:54 PM
devices and pipes siemens Linux - General 1 03-23-2005 03:30 AM
pipes on Suse AdamTheFirst Linux - Software 1 11-04-2004 02:07 PM
Interleaving using pipes AquamaN Programming 1 09-28-2003 04:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration