Operating System - HP-UX
1752422 Members
5876 Online
108788 Solutions
New Discussion юеВ

How to write/read using pipe in C?

 
KiatLeong Len
Occasional Contributor

How to write/read using pipe in C?

I am trying to create 2 programs to write and read to/from pipe file in HP-UX 10.20. Does anyone have any source code to share? Thanks.

Where can i find more information about this topic?

Can anyone advise where can i find RealTime Programming manual by HP? I remember seeing this manual a few years ago. This manual shows how to use pipe, share memory, semaphore and etc..

Best regards.

Len
3 REPLIES 3
Dan Hetzel
Honored Contributor

Re: How to write/read using pipe in C?

Hi Len,

To write to a pipe using a C program, you need to open the pipe first.
This is done through the popen() call.
FILE *popen(const char *command, const char *type);

The popen() call will start a command and return a FILE descriptor that you may use in subsequent fread and fwrite calls (depending on the pipe r/w type ) like any other file.

Use the pclose() to close the pipe.

Best regards,

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com
RikTytgat
Honored Contributor

Re: How to write/read using pipe in C?

Hi,

A great book about Unix system programming is

'Advanced Programming in the Unix Environment' by Richard Stevens. It covers all these issues.

(Addison-Wesley Pub Co; ISBN: 0201563177 ; Dimensions (in inches): 2.35 x 9.67 x 7.92 )


Bye,
Rik
Andy Bennett
Valued Contributor

Re: How to write/read using pipe in C?

Another good book by Stevens that has a section on Pipes is "Unix Network Programming: Volume 2: Interprocess Communications". Have a look at site:

http://www.kohala.com/start

This was Stevens' own website, but is now maintained by one of his co-authors and it contains descriptions of his books and downloadable source examples that accompany them. There'll be some pipe demo code in there.

As far as the realtime manual goes I couldn't find one on HP's usual sites, http://docs.hp.com and http://devresource.hp.com. It is probably worth your trying there in case the name isn't quite as you've written. It is probably worth checking the other Unix vendors' sites too since the various companies often produce similar manuals a lot of which, depending on the topic, is not platform specific.