资源描述:
《进程间消息传递.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、F4键显示进程之间的消息一、实验目的了解进程间消息传递原理。二、实验要求通过F4键截获进程表中所有进程,并显示进程发送接收消息的总次数。三、实验内容1、定义消息矩阵:逻辑上系统进程表数组下标是从负数开始,而C语言中下标不能为负数,需要引入头文件,matrix负责记录进程间通信的次数。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、定义函数原型/*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处加入函数定义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