您好,欢迎访问三七文档
西安电子科技大学《操作系统原理》实验报告题目:进程通信实验报告班级:030912姓名:王增祥学号:03091168实验内容补充说明:一、分析和设计1.理论分析每个Windows进程都是由一个执行体进程块(EPROCESS)表示。API函数CreatProcess可以创建进程,采用管道技术可以实现进程间的相互通信。建立pipe,进程以及其子进程就可以对该管道进程读写共享,管道读写操作利用,write、read、close进行。父进程利用pipe发送消息,子进程利用该pipe接收父进程发来的消息;子进程利用管道向父进程发送应答,父进程利用该pipe接受应答。2.总体设计1、利用CreatProcess函数创建进程。2、创建管道,实现进程间的通信二、详细实现1、创建界面,采用Botton、列表框等控件创建父子界面如下图:父进程界面:子进程界面:其中父进程各个空间创建类向导如图:子进程创建类向导如图:2.父进程编写(1)创建管道:(2)创建子进程:(3)消息发送(4)消息接受3.子进程编写(1)发送消息(2)读消息三、实验结果点击创建子进程按钮:在创建子进程之后进行进程间的通信如下图四、心得体会1、从试验的角度了解了进程间是怎样利用管道进行通信的,了解了进程间通信的实际过程2、进一步掌握了MFC的初步编程技巧,知道了怎样调试程序。3进一步了解了,API函数的应用,明白了怎样进行界面编程。4、进一步熟悉了在进行进程通信的编写过程中的各个细节。六、附录Process_Father.cpp#includestdafx.h#includeProcess_Father.h//包含已编写的Process_Father.h头文件#includeProcess_FatherDlg.h//包含已编写的Process_FatherDlg.h头文件//进行宏定义#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif//创建父进程BEGIN_MESSAGE_MAP(CProcess_FatherApp,CWinApp)//{{AFX_MSG_MAP(CProcess_FatherApp)//NOTE-theClassWizardwilladdandremovemappingmacroshere.//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!//}}AFX_MSGON_COMMAND(ID_HELP,CWinApp::OnHelp)END_MESSAGE_MAP()//CProcess_FatherAppconstructionCProcess_FatherApp::CProcess_FatherApp(){//TODO:addconstructioncodehere,//PlaceallsignificantinitializationinInitInstance}//TheoneandonlyCProcess_FatherAppobjectCProcess_FatherApptheApp;//CProcess_FatherAppinitializationBOOLCProcess_FatherApp::InitInstance(){AfxEnableControlContainer();#ifdef_AFXDLLEnable3dControls();//CallthiswhenusingMFCinasharedDLL#elseEnable3dControlsStatic();//CallthiswhenlinkingtoMFCstatically#endifCProcess_FatherDlgdlg;m_pMainWnd=&dlg;intnResponse=dlg.DoModal();if(nResponse==IDOK){//TODO:Placecodeheretohandlewhenthedialogis//dismissedwithOK}elseif(nResponse==IDCANCEL){//TODO:Placecodeheretohandlewhenthedialogis//dismissedwithCancel}//Sincethedialoghasbeenclosed,returnFALSEsothatweexitthe//application,ratherthanstarttheapplication'smessagepump.returnFALSE;}Process_FatherDlg.cpp//Process_FatherDlg.cpp:implementationfile//#includestdafx.h#includeProcess_Father.h#includeProcess_FatherDlg.h#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif///////////////////////////////////////////////////////////////////////////////CAboutDlgdialogusedforAppAboutclassCAboutDlg:publicCDialog{public:CAboutDlg();//DialogData//{{AFX_DATA(CAboutDlg)enum{IDD=IDD_ABOUTBOX};//}}AFX_DATA//ClassWizardgeneratedvirtualfunctionoverrides//{{AFX_VIRTUAL(CAboutDlg)protected:virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport//}}AFX_VIRTUAL//Implementationprotected://{{AFX_MSG(CAboutDlg)//}}AFX_MSGDECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg():CDialog(CAboutDlg::IDD){//{{AFX_DATA_INIT(CAboutDlg)//}}AFX_DATA_INIT}voidCAboutDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CAboutDlg)//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)//{{AFX_MSG_MAP(CAboutDlg)//Nomessagehandlers//}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CProcess_FatherDlgdialogCProcess_FatherDlg::CProcess_FatherDlg(CWnd*pParent/*=NULL*/):CDialog(CProcess_FatherDlg::IDD,pParent){//{{AFX_DATA_INIT(CProcess_FatherDlg)//}}AFX_DATA_INIT//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32m_hIcon=AfxGetApp()-LoadIcon(IDR_MAINFRAME);}voidCProcess_FatherDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CProcess_FatherDlg)DDX_Control(pDX,IDC_BT_CreateChildProcess,m_BT_CreateChildProcess);DDX_Control(pDX,IDC_Send,m_Send);DDX_Control(pDX,IDC_LISTBOX_Record,m_LISTBOX_Record);DDX_Control(pDX,IDC_EDIT_Message,m_EDIT_Message);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CProcess_FatherDlg,CDialog)//{{AFX_MSG_MAP(CProcess_FatherDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BT_CreateChildProcess,OnBTCreateChildProcess)ON_BN_CLICKED(IDC_Send,OnSend)//}}AFX_MSG_MAPON_MESSAGE(WM_CHILD_SEND,OnReceiveMsg)END_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CProcess_FatherDlgmessagehandlersBOOLCProcess_FatherDlg::OnInitDialog(){CDialog::OnInitDialog();//AddAbout...menuitemtosystemmenu.//IDM_ABOUTBOXmustbeinthesystemcommandrange.ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX0xF000);CMenu*pSysMenu=GetSystemMenu(FALSE);if(pSysMenu!=NULL){CStringstrAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if(!strAboutMenu.IsEmpty()){pSysMenu-AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);}}//Settheiconforthisdialog.Theframeworkdoesthisautomatically//whentheapplication'smainwindowisnotadialogSetIcon(m_hIcon,TRUE);//SetbigiconSetIcon(m_hIcon,FALSE);//Setsmallicon//TODO:AddextrainitializationherereturnTRUE;//returnTRUEunlessyousetthefocustoacontrol}voidCProcess_FatherDlg::OnSysCommand(UINTnID,LPARAMlParam){if((nID&0xFFF0)==IDM_ABOUTBOX){CAboutDlgdlgAbout;dlgAbout.DoModal();}else{CDialog::OnSysCommand(nID,lParam);}}//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecode
本文标题:进程通信实验报告
链接地址:https://www.777doc.com/doc-6712146 .html