linux并发程序设计 实训小结,急求!!!!字数500~600

要求一篇linux c语言下并发程序设计的实训小结,要求写写编写过程中遇到的问题,觉得应该注意的地方,自己的心得体会,写的好一定加分!!!!

实验6 Linux进程并发程序设计

1 实验目的:
掌握Linux环境下的进程并发程序及管道应用程序的编写要点。

2 实验内容和实验步骤:
(1) 调试并运行3.10的并发程序设计实例,显示结果是什么,并分析之。

通过pipeline.c这个文件,调用child1.c和father1.c这两个程序,father1.c写入管理,然后再通过child1.c读管道,因此输出为以上结果。

(2) 编写一个并发程序,父进程打印“The Parent is running”;子进程打印“The Child is running”;

#include<stdio.h>

#include<unistd.h>

main()

{

int p1;

while((p1=fork())==-1);

if(p1>0)

{

wait(0);

printf("The Parent is running.\n");

}

else

{

printf("The Child is running.\n");

exit(0);

}

}

结果为:

The Child is running.

The Parent is running.

(3) 编写一个管道应用程序,父进程通过管道提供字符串“put the string into the pipe.”给子进程,子进程通过管道接收这条信息,然后打印输出。

#include<stdio.h>

#include<unistd.h>

main()

{

int p1,fd[2];

char outpipe[50]; //定义读缓冲区

char inpipe[50]="put the string into the pipe."; //定义写缓冲区

pipe(fd); //创建无名管道fd

while((p1=fork())==-1);

if (p1>0) //父进程返回

{

write(fd[1],inpipe,50); //写信息到管道

wait(0);

}

else //子进程返回

{

read(fd[0],outpipe,50); //从管道读信息到读缓冲区

printf("%s\n",outpipe); //显示读到的信息

exit(0);

}

}

结果为:

put the string into the pipe.

3.实验要求:写出实验报告并将结果上传到FTP SERVER上自己的作业目录。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-26
自己找本并行编程或者多线程书看看 里面会有很多的问题 成功的程序写不出来问题还不好找吗
第2个回答  2011-06-26
这个很好写的,写一下实训内容,在加点自己的感受,就OK了
相似回答