问题
Write a program for this------>>>>>>
- One program will open a pipe, write a number to pipe.
- Other program will open the same pipe, will read the number and print them.
- Close both the pipes.
how can i write a program based on this any one knows it then please help me...!!!!
回答1:
I think what you're looking for is:
echo <number you want to use> (or output from program) | <program you want to pipe into>
For instance:
echo 5 | more
which will simply display:
5
The "|" is your pipe; it redirects output from the left to the right connecting their standard streams, which usually does not include stderr.
Hope that helps.
回答2:
A pipe is probably the simplest IPC solution under Linux; so talking about a pipe i like talking about a specific interprocess communication solution.
The IPC lives in the kernel space and it's managed by the kernel itself, works in 1 direction and only between a caller and a callee, it's unidirectional.
for more you should just read a good article about the pipes and the IPC under Linux, you will found a gozillion of articles on the internet, for a short example you can go here.
来源:https://stackoverflow.com/questions/18087047/program-based-on-pipe-in-linux