导航:首页 > 编程语言 > 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并行编程相关的资料

热点内容
bytedance这个文件夹是什么意思呢 浏览:585
算法站的客体 浏览:73
src文件夹c语言怎么运行 浏览:19
怎么把已安装的app放到桌面 浏览:942
如何查看苹果手机app是否取消订阅 浏览:769
u盘加密之后手机可以打开吗 浏览:42
单片机串口发射怎么回事 浏览:474
程序员假装自己很忙 浏览:798
程序员能力关键词 浏览:617
plc编程高级视频教程 浏览:614
java递归求n 浏览:88
python绝对路径导入 浏览:131
nex5g加密 浏览:979
18的空岛服务器地址 浏览:90
程序员要学什么硬件 浏览:668
股票涨跌源码怎么看 浏览:580
加密软件做法 浏览:59
美国程序员有多少中国人 浏览:741
人民日报app里怎么看新闻早班车 浏览:589
忘了app怎么办 浏览:533