问题描述
我已经编写了用于在Linux中将数字写入管道的代码.如下所示,但是显示错误,有人可以帮我吗?
I have written my code for writing a number to pipe in linux. it is as under,but it is showing errors,can anyone help me on this.
基本上该程序的问题陈述如下:-一个程序将打开管道,并在管道中写入一个数字. -其他程序将打开相同的管道,将读取该数字并进行打印. -关闭两个管道
Basically the problem statement for the program is as below:-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
int main()
{
int number;
FILE *fout;
fout = popen(" ","w");
pclose(fout);
return 0;
}
现在我的问题是我应该在popen命令选项中给出什么命令(如上面的空白所示),以便我可以继续进行并向管道写一个数字.
Now my question is what command should i give in the popen command option (as shown blank above) so as i can proceed further and write a number to pipe.
推荐答案
您不太了解IPC和管道的工作方式.请阅读一本好书:高级Linux编程关于这些问题的几章内容.
You don't understand well how IPC and pipes work; please read a good book: Advanced Linux Programming has several chapters on these issues.
库函数 popen(3)运行命令.很可能您的系统上没有p
命令.我猜fp
为NULL并且errno
被设置.
The library function popen(3) runs a command. Very probably, you don't have a p
command on your system. I guess fp
is NULL and errno
is set.
popen
使用的是 pipe(2), 叉(2), dup2(2), execve(2)和/bin/sh -c
等
popen
is using pipe(2), fork(2), dup2(2), execve(2) and /bin/sh -c
etc
这篇关于在Linux中使用管道进行进程间通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!