I tried searching on the net, but there are hardly any resources. A small example would suffice.
EDIT I mean, two different C programs communicating with each other. One program should send "Hi" and the other should receive it. Something like that.
Join Stack Overflow to learn, share knowledge, and build your career.
|
A regular pipe can only connect two related processes. It is created by a process and will vanish when the last process closes it. A named pipe, also called a FIFO for its behavior, can be used to connect two unrelated processes and exists independently of the processes; meaning it can exist even if no one is using it. A FIFO is created using the Examplewriter.c
reader.c
Note: Error checking was omitted from the above code for simplicity. |
|||||||||||||||||||||
|
|
From Creating Pipes in C, this shows you how to fork a program to use a pipe. If you don't want to fork(), you can use named pipes. In addition, you can get the effect of
|
|||||
|
And read:
But, I think that
|
||||
|
|
|
What one program writes to stdout can be read by another via stdin. So simply, using c, write
|
|||
|
|
The important steps in this program are:
|
|||||
|
|
first, have program 1 write the string to stdout (as if you'd like it to appear in screen). then the second program should read a string from stdin, as if a user was typing from a keyboard. then you run: program_1 | program_2 |
|||
|
|
|
This answer might be helpful for a future Googler.
You can find an advanced two-way pipe call example here. |
|||
|
|
ls | grep ".o"? Perhaps a bit more explanation of what you do mean would help... – Jerry Coffin May 6 '10 at 21:09