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

热点内容
胸7椎体轻度压缩 浏览:108
sk5服务器什么意思 浏览:554
什么是廊坊交警app 浏览:294
衣柜造价算法 浏览:984
默认的web服务器地址 浏览:694
单片机与发光二极管 浏览:320
pythonwebmodule 浏览:328
空调压缩机不停了 浏览:115
python序列怎么取 浏览:199
线上数据库加密怎么查询 浏览:794
js中数据加密 浏览:470
穴pdf 浏览:548
阿里云服务器云数据库还需要吗 浏览:146
在程序设计中常用的算法有哪些 浏览:977
为什么苏州公积金app一直维护 浏览:805
有ip地址但是dhcp服务器 浏览:446
三星手机加密中断怎么回事 浏览:538
训练模型init源码 浏览:840
程序编译是谁的功能 浏览:505
qq收藏怎样设置加密 浏览:291