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

熱點內容
微信應用鎖加密 瀏覽:451
數字英雄對程序員的影響 瀏覽:761
程序員培訓學校排名 瀏覽:586
oppo手機如何解開微信的加密 瀏覽:37
學校論文答辯源碼 瀏覽:66
rp在單片機中 瀏覽:177
linux軟體運行命令 瀏覽:354
stcid加密程序 瀏覽:139
把解壓包子放到水裡 瀏覽:286
phpmongodb連接池 瀏覽:945
日本解壓捏泡泡紙 瀏覽:121
環保參比演算法 瀏覽:413
解壓中的刪掉是什麼意思 瀏覽:766
王牌競速什麼時候能停止維修伺服器 瀏覽:488
pdf閱讀器官方 瀏覽:88
程序員那麼愛心 瀏覽:305
字元a經過md5加密 瀏覽:420
綠色的小蝴蝶是個什麼app 瀏覽:18
python編程輸入數字輸出年月日英文 瀏覽:631
程序員槍手 瀏覽:748