我在做操作系统课程,我们应该学习如何使用管道在进程之间传输数据。在Linux中使用管道C使用管道
我们给了这段简单的代码,演示了如何使用管道,但我很难理解它。
#include
#include
#include
main()
{
int pipefd [2], n;
char buff[100] ;
if(pipe(pipefd) < 0)
{
printf("can not create pipe \n");
}
printf("read fd = %d, write fd = %d \n", pipefd[0], pipefd[1]);
if (write (pipefd[1],"hello world\n", 12)!= 12)
{
printf("pipe write error \n");
}
if( (n = read (pipefd[0] , buff, sizeof (buff) )) <= 0)
{
printf("pipe read error \n");
}
write (1, buff, n) ;
exit (0);
}
是什么写入功能吗?它似乎发送数据到管道,并将其打印到屏幕上(至少看起来像第二次写入功能被称为它)。
有没有人有任何关于这方面的知识,FIFO,信号,在C中使用的其他基本的Linux命令学习的好网站的建议?
2010-05-10
Meir