Program based on pipe in Linux

佐手、 提交于 2019-12-29 09:41:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!