2023年實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)七_(dá)第1頁(yè)
2023年實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)七_(dá)第2頁(yè)
2023年實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)七_(dá)第3頁(yè)
2023年實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)七_(dá)第4頁(yè)
2023年實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)七_(dá)第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

浙江大學(xué)城市學(xué)院實(shí)驗(yàn)報(bào)告課程名稱操作系統(tǒng)原理實(shí)驗(yàn)實(shí)驗(yàn)項(xiàng)目名稱實(shí)驗(yàn)七進(jìn)程通信一一消息隊(duì)列學(xué)生姓名潘唯帆專(zhuān)業(yè)班級(jí)計(jì)算1003學(xué)號(hào)31001172實(shí)驗(yàn)成績(jī)指導(dǎo)老師(署名)日期注意:務(wù)請(qǐng)保存好各自的源代碼,已備后用。請(qǐng)上傳到BB平臺(tái)。一.實(shí)驗(yàn)?zāi)康暮鸵?guī)定.了解Linux系統(tǒng)的進(jìn)程間通信機(jī)構(gòu)(IPC);.理解Linux關(guān)于消息隊(duì)列的概念;.掌握Linux支持消息隊(duì)列的系統(tǒng)調(diào)用;.鞏固進(jìn)程同步概念。二、實(shí)驗(yàn)內(nèi)容實(shí)現(xiàn)并發(fā)進(jìn)程間消息的發(fā)送與接受。三、實(shí)驗(yàn)環(huán)節(jié)1、消息的發(fā)送與接受1)。編譯運(yùn)營(yíng)給出的c1ient.c和server.c,觀測(cè)運(yùn)營(yíng)結(jié)果。四、討論、心得記錄實(shí)驗(yàn)感受、上機(jī)過(guò)程中碰到的困難及解決辦法、遺留的問(wèn)題、意見(jiàn)和建議等。文件⑹編輯⑹查看&)終端①標(biāo)簽⑧幫助?)[rootolocalhostpanweifanj=gcc-oserverserver.cserver.c:Infunctionserver:server.c:22:警告:隱式聲明與內(nèi)建函數(shù)f)rintf不兼容server.c:26:警告:隱式聲明與內(nèi)建函數(shù)exit不兼容[rootelocalhostpanweifan]=./server(server)received(server)received(server)received(server)received(server)received(server)received(server)received(server)received(server)received(server)received[root?localhostpanweifan]=文件6編輯⑹查看Q)終端①標(biāo)簽⑥幫助出)[root?localhostpanwetfan]2gcc-oclientcltent.cclient.c:InfunctionClient":client.c:22:警告:隱式聲明與內(nèi)建函數(shù)prtntf不兼容client.c:26:警告:隱式聲明與內(nèi)建函數(shù)exif不兼容[root^localhostpanweifan]=./client(client)sent(cltent)sent(client)sent(clienl)sent(client)sent(clienl)sent(client)sent(client)sent(client)sent(client)sent[root?localhostpanweifan)-12)請(qǐng)給上述程序添加同步控制,實(shí)現(xiàn)同步運(yùn)營(yíng)。

root@localhost:/panweifan文件的編輯?查看。終端①標(biāo)簽⑧幫助電)[root?localhostpanweifan1=./server(server)received(server)received(server)received(server)received(server)received(server)received(server)received(server)received(server)received(server)receive。|root?localhostpanweiianj-二#inc1udc<sys/typcs.h>#inelude<sys/msg.h>#inelude<sys/ipc.h>#defineMSGKEY75structmsgform(dongmtype;charmtcxt[1000];}msg;intmsgqid;voidserver()(/*創(chuàng)建75#消息隊(duì)列*/omsgqid=msgget(MSGKEY,0777|IPC_CREAT);ado。/*接受消息*/0msgrcv(msgqid,&msg,1030,0,0);printf("(server)received\n");dockf(msg,0,0);。}while(msg.mtype!=1);/*刪除消息隊(duì)列,歸還資源*/msgctl(msgqid,IPC_RMID,0);°exit(O);)main()server();#include<sys/types.h>#inelude<sys/msg.h>#includc<sys/ipc.h>efineMSGKEY75structmsgform(longmtype;ocharmtext[1000];)msg;intmsgqid;voidclicnt()(nti;/*打開(kāi)75#消息隊(duì)列*/?msgqid=msgget(MSGKEY,0777);ofor(i=10;i>=l;i--)(wmsg.mtype=i;。printf("(client)sent\n");/*發(fā)送消息*/sgsnd(msgqid,&msg,1024,0);1ockf(msgJ,0);0}exit(0);niain()clicnt();2、編寫(xiě)程序:使用消息隊(duì)列,實(shí)現(xiàn)具有下列功能兩個(gè)程序(進(jìn)程):1)程序A負(fù)責(zé)接受用戶來(lái)自鍵盤(pán)的輸入;2)程序B負(fù)責(zé)實(shí)時(shí)輸出用戶由程序A接受的字符。程序A和程序B可分別在兩個(gè)進(jìn)程上同時(shí)運(yùn)營(yíng)。root@localhost:/panwelfan文件6編轉(zhuǎn)⑥查看9終端①標(biāo)簽⑧幫助回[rootolocalhostpanweifan)^./clientIhaveadreamthatonedayeveryonewilllivehappy-liferoot@localhost:/panwelfan文件⑹編輯⑹查看Q)終端①標(biāo)簽⑥幫助回[root?localhostpanweifan]-./server(server)received:I(server)received:have(server)received:a(server)received:dream(server)received:that(server)received:one(server)received:day(server)received:everyone(server)received:will(server)received:1ive(server)received:a(server)received:happy(server)received:1ife(server)received:.inc1ude<sys/types.h>include<sys/msg.h>inelude<sys/ipc.h>#defineMSGKEY75structmsgform(010ngmtype;charmtext[1000];}msg;intmsgqid;voidclient()inti;。/*打開(kāi)75#消息隊(duì)列*/?msgqid=msggei(MSGKEY,0777);?for(i=100;i>=1;i—)(Mmsg.mtype=i;?scanf("%s",msg.mtcxt);。/*發(fā)送消息*/wmsgsnd(msgqid,&msg,1024,0);?1ockf(msg,1,0);exit(0);)main()(client();inc1ude<sys/types.h>inc1ude<sys/msg.h>inc1ude<sys/ipc.h>defineMSGKEY75structmsgform{longmtype;charmtext[1000];

intmsgqid;voidserver()(。/*創(chuàng)建75#消息隊(duì)列*/msgqid=msggel(MSGKEY,0777|IPC_CREAT);do/*接受消息*/msgrcv(msgqid,&msg.l030,0,0);%s\n0,msg.mt

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論