導航:首頁 > 編程語言 > 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並行編程相關的資料

熱點內容
易語言源碼轉python 瀏覽:364
程序員日祝福 瀏覽:883
阿里tv助手app哪裡下載 瀏覽:187
app活動怎麼關 瀏覽:202
java改變map 瀏覽:348
解壓鋼琴呂恆 瀏覽:991
程序員怎麼獲取被動收入 瀏覽:568
能不能別讓編程貓打電話給我了 瀏覽:687
量線突破指標源碼 瀏覽:458
雲伺服器阿里環境搭建 瀏覽:123
錐孔是怎麼編程的 瀏覽:133
加強箍和加密箍的區別 瀏覽:897
怎麼在騰訊伺服器上傳文件 瀏覽:643
公司門戶app安卓怎麼卸載 瀏覽:990
單片機中段源 瀏覽:143
電腦桌面文件加密要怎樣解除 瀏覽:963
quickfoxapp的商場在哪裡 瀏覽:2
單片機與pc機通信畢業設計 瀏覽:221
wan口的伺服器默認賬號是什麼 瀏覽:177
取小數位數php 瀏覽:716