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

下載本文檔

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

文檔簡介

浙江大學(xué)城市學(xué)院實(shí)驗(yàn)報(bào)告課程名稱操作系統(tǒng)原理實(shí)驗(yàn)實(shí)驗(yàn)項(xiàng)目名稱實(shí)驗(yàn)七進(jìn)程通信一一消息隊(duì)列學(xué)生姓名潘唯帆專業(yè)班級計(jì)算1003學(xué)號31001172實(shí)驗(yàn)成績指導(dǎo)老師(署名)日期注意:務(wù)請保存好各自的源代碼,已備后用。請上傳到BB平臺。一.實(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)營給出的c1ient.c和server.c,觀測運(yùn)營結(jié)果。四、討論、心得記錄實(shí)驗(yàn)感受、上機(jī)過程中碰到的困難及解決辦法、遺留的問題、意見和建議等。文件⑹編輯⑹查看&)終端①標(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)請給上述程序添加同步控制,實(shí)現(xiàn)同步運(yùn)營。

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;/*打開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、編寫程序:使用消息隊(duì)列,實(shí)現(xiàn)具有下列功能兩個(gè)程序(進(jìn)程):1)程序A負(fù)責(zé)接受用戶來自鍵盤的輸入;2)程序B負(fù)責(zé)實(shí)時(shí)輸出用戶由程序A接受的字符。程序A和程序B可分別在兩個(gè)進(jìn)程上同時(shí)運(yùn)營。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;。/*打開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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論