資源描述:
《進(jìn)程間消息傳遞.doc》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、F4鍵顯示進(jìn)程之間的消息一、實(shí)驗(yàn)?zāi)康牧私膺M(jìn)程間消息傳遞原理。二、實(shí)驗(yàn)要求通過F4鍵截獲進(jìn)程表中所有進(jìn)程,并顯示進(jìn)程發(fā)送接收消息的總次數(shù)。三、實(shí)驗(yàn)內(nèi)容1、定義消息矩陣:邏輯上系統(tǒng)進(jìn)程表數(shù)組下標(biāo)是從負(fù)數(shù)開始,而C語言中下標(biāo)不能為負(fù)數(shù),需要引入頭文件,matrix負(fù)責(zé)記錄進(jìn)程間通信的次數(shù)。b5E2RGbCAP在/kernel/glo.h處加入矩陣定義:。。。#include/*為了引用NR_TASKS*/。。。EXTERNintmatrix[NR_TASKS+NR_PROCS][NR_TA
2、SKS+NR_PROCS]。p1EanqFDPw。。。2、/kernel/system/do_getinfo.c中加入程序段caseGET_MATRIX:{length=sizeof(matrix>。src_phys=vir2phys(matrix>。break。}3、在/servers/is/dmp_kernel.c處加入矩陣定義PUBLICintmatrix[NR_TASKS+NR_PROCS][NR_TASKS+NR_PROCS]。DXDiTa9E3d8/84、在/servers/is/proto.h處
3、定義函數(shù)原型/*dmp_kernel.c*/_PROTOTYPE(voidproctab_dmp,(void>>。_PROTOTYPE(voidmemmap_dmp,(void>>。_PROTOTYPE(voidprivileges_dmp,(void>>。_PROTOTYPE(voidsendmask_dmp,(void>>。_PROTOTYPE(voidimage_dmp,(void>>。_PROTOTYPE(voidirqtab_dmp,(void>>。_PROTOTYPE(voidkmessages_
4、dmp,(void>>。_PROTOTYPE(voidsched_dmp,(void>>。_PROTOTYPE(voidmonparams_dmp,(void>>。_PROTOTYPE(voidkenv_dmp,(void>>。_PROTOTYPE(voidtiming_dmp,(void>>。_PROTOTYPE(voiddisp_mess,(void>>。5、在/servers/is/dmp_kernel.c處加入函數(shù)定義voiddisp_mess(void>{inti,j,r,d。staticintol
5、di=0。staticintoldj=0。intresult。intmatrix[NR_TASKS+NR_PROCS][NR_TASKS+NR_PROCS]。RTCrpUDGiTresult=sys_getmatrix(&matrix>。if(result!=OK>{report("IS","warning:couldn'tgetcopyofmatrix",result>。5PCzVD7HxAreturn。}/*elseprintf("Wellcome,F4pressed.">。*/result=sys_
6、getproctab(proc>。if(result!=OK>{report("IS","warnng:couldn'tgetcopyofproctab",result>。jLBHrnAILgreturn。}r=0。for(i=oldi。i{if(!isemptyp(&proc[i]>>{d=0。for(j=oldj。jif(matrix[i][j]>0/*&&!isemptyp(&proc[j]>*/>{xHAQX74J0Xd=1。bre
7、ak。}if(d>printf("%s->",proc[i].p_name>。8/8for(j=oldj。j{if(matrix[i][j]>0/*&&!isemptyp(&proc[j]>*/>{printf("(%s,%d>",proc[j].p_name,matrix[i][j]>。r++。if(r>=22>{printf("--more--r">。oldi=j==NR_PROCS-1?i+1:i。oldj=j==NR_PROCS-1?0:j+1。return。}}
8、}}}oldi=oldj=0。}6、在/servers/is/dmp.c處修改功能鍵F4的功能{F4,disp_mess,"displaymessagepassing"},7、在/usr/include/minix/syslib.h中加入sys_getmatrix的聲明#definesys_getmatrix(dst>sys_getinfo(GET_MATRIX,dst,0,0,0>LDAYtRyK