ImageVerifierCode 换一换
格式:DOCX , 页数:13 ,大小:271.29KB ,
资源ID:3814209      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3814209.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(进程间相互通信.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

进程间相互通信.docx

1、进程间相互通信集 美 大 学诚毅学院信息工程系实 验 报 告课程名称计算机操作系统序号名称 进程间通信(IPC)姓名孙幸杰学号2011957032专业计算1191日期2011.11.6成绩教师洪联系评语:1.实验目的:掌握用pipe进行进程间通信;掌握用共享内存进行进程间通信;理解父进程与子进程各处独立的地址空间,父进程与子进程,它们只能通过pipe、共享内存等方式进行通信;2实验环境Win7系统,vmware虚拟机下运行的Linux。3.实验内容应用Linux共享内存机制和管道机制, 实现两个进程间相互传递一个学生的记录,包括:1. 学号: SID, char型, 8位2. 姓名: NAME

2、, char型, 8位3. 年龄: Age, int型4. 专业: Specialty, char型, 8位5. 班级: Class, char型, 4位一个记录约30个字节。4实验程序1.Shm1.c#include #include #include #include #include #include #include typedef struct char name4; char sid8; char specialty8; char class4; int age;people;int main(int argc, char *argv) int shm_id,i; key_t ke

3、y; char temp; people *p_map; char *path = ./shm1.c; /* 使用 ftok根据path和作为项目标识符的单个字符生成key值确保进程间使用相同的 key 使用相同key值的shmget只会在第一次时创建新结构 */ key = ftok(path,0); if(key = -1) perror(ftok error n); return -1; shm_id = shmget(key,4096,IPC_CREAT); if(shm_id = -1) perror(shmget error n); return -1; p_map = (peop

4、le*)shmat(shm_id,NULL,0); temp = a; for(i = 0; i 10; i+) temp +=1; memcpy(*(p_map+i).name,&temp,1); memcpy(*(p_map+i).sid,&temp,1); memcpy(*(p_map+i).specialty,&temp,1); memcpy(*(p_map+i).class,&temp,1); (*(p_map+i).age = 20+i; system(ipcs -m); if(shmdt(p_map) = -1) perror(detach error); system(ipcs

5、 -m);2.shm2.c/*System V共享内存区是放在内核当中的,因此在内核重新引导之前,对数据的修改是一直保持的,这也是我们的实验能够实现的原因,因为在第二个进程起动时,第一个进程已经运行结束了.*/#include #include #include #include #include /*完成从共享内存区的读出*/typedef struct char name4; char class4; char specialty4; char sid4; int age;people;int main (int argc, char* argv) int shm_id, i; key_t

6、 key; people *p_map; char *path = ./shm1.c; key = ftok(path,0); if(key = -1) perror(ftok error n); return -1; shm_id = shmget(key,4096,IPC_CREAT); if(shm_id = -1) perror(shmget error); return -1; p_map = (people*)shmat(shm_id,NULL,0); for(i=0; i10; i+) printf(name:%st,(*(p_map+i).name); printf(speci

7、alty:%st,(*(p_map+i).specialty); printf(sid:%st,(*(p_map+i).sid); printf(class:%st,(*(p_map+i).class); printf(age:%dn,(*(p_map+i).age); system(ipcs -m); if(shmdt(p_map) = -1) perror(shmdt errorn); return -1; system(ipcs -m); exit(EXIT_SUCCESS);3Pipe.c#include #include #include #include int pfd2;int

8、process1();int process2();int main() int i,status; if(pipe(pfd)0) printf(pipe create error!n); exit(1); else printf(Pipe is created successfully!n); if(fork()=0) process1(); if(fork()=0) process2(); close(pfd0); close(pfd1); for(i=0;i2;i+) wait(&status); exit(0); int process1() printf(Process 1 is r

9、unning.n); close(pfd0); int i=0; char w_buf5; for(i=1;i10;i+) sleep(3); strcpy(w_buf,aaa0); if(write(pfd1,w_buf,4)=-1) printf(Write to pipe errorn); close(pfd1); printf(Process 1 is over!n); exit(0); int process2() printf(Process 2 is running.n); close(pfd1); char r_buf5; while(1) sleep(1); strcpy(r_buf,kkk0); if(read(pfd0,r_buf,4)=0) break; printf(Get %s from pipe in process 2.n,r_buf); close(pfd0); printf(Process 2 is over!n); exit(0); 5 .实验结果及其分析Shm1.c输入:运行:Shm2.c输入:运行:Pipe.c输入:运行:6实验小结我觉得老师可以教我们怎么把虚拟机与自己的电脑连接起来的方法。可以把自己电脑上的东西复制到虚拟机上面去。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1