Linux环境下,进程间通信(一) :
1、编写一段C语言程序使其完成:父子进程通过无名管道传递三条消息:
*管道文件的测试程序开始。
*管道文件测试正在进行。
*管道文件测试结束。
接收进程收到信息后将它们送到标准输出文件上。
2、用 pipe( )创建一个管道文件,然后用fork(
)创建两个生产进程和两个消费进程,它们之间通过pipe(
)传递信息。
部分参考代码:
#include
#include
#include
#include
#define BUFFSIZ sizeof("Start the test of pipe
file")
main( )
{
int i,f_des[2];
char message[3][BUFFSIZ]={"Start the test of
pipe file","Test is going",
"Test ends"};
if(pipe(f_des)==-1)
{
printf("pipe");
exit(2);
}
switch(fork( ))
{
case -1:
printf("Fork");
exit(3);
case 0:
close(f_des[1]);
for(i=0;i<3;