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

熱點內容
javacdataxml 瀏覽:943
本機tcp伺服器地址 瀏覽:426
切換pdf 瀏覽:92
iturns下載的app在哪裡 瀏覽:639
雲起書院App在哪裡 瀏覽:614
怎麼對hex文件進行加密 瀏覽:285
pdf少年時 瀏覽:953
兩個同名文件夾同步 瀏覽:630
拍照文件夾哪個好用 瀏覽:91
文件夾和書包 瀏覽:511
解壓歸檔拿登記證 瀏覽:225
去體驗解壓房 瀏覽:613
單片機一鍵中斷響應 瀏覽:646
唐浩明pdf 瀏覽:845
程序員土木 瀏覽:73
android如何與web伺服器交互 瀏覽:611
蘋果小風扇app怎麼下 瀏覽:958
杭州it程序員對身體好不好 瀏覽:537
高新區編程加盟找哪家 瀏覽:33
伺服器什麼樣的好賣 瀏覽:152