导航:首页 > 编程语言 > linux并行编程

linux并行编程

发布时间:2023-11-09 15:09:05

1. c++如何并行编程

多线程才可以啊,好比一个人的大脑,计算机也不能同时工作的,即使是多线程,也是交替使用cpu的资源的

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

实验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上自己的作业目录。

阅读全文

与linux并行编程相关的资料

热点内容
基于51系列单片机的智能家居 浏览:581
看新闻看哪个app 浏览:270
android编辑对话框 浏览:304
出租天津服务器云空间 浏览:789
cmd命令结束进程 浏览:443
程序员逗比图片大全 浏览:512
免编程游戏引擎 浏览:372
微信应用锁加密 浏览:459
数字英雄对程序员的影响 浏览:761
程序员培训学校排名 浏览:586
oppo手机如何解开微信的加密 浏览:45
学校论文答辩源码 浏览:74
rp在单片机中 浏览:186
linux软件运行命令 浏览:354
stcid加密程序 浏览:147
把解压包子放到水里 浏览:294
phpmongodb连接池 浏览:953
日本解压捏泡泡纸 浏览:129
环保参比算法 浏览:421
解压中的删掉是什么意思 浏览:774