操作系统实习.docx
- 文档编号:356411
- 上传时间:2022-10-09
- 格式:DOCX
- 页数:13
- 大小:17.99KB
操作系统实习.docx
《操作系统实习.docx》由会员分享,可在线阅读,更多相关《操作系统实习.docx(13页珍藏版)》请在冰豆网上搜索。
操作系统实习
操作系统期末实习
院系:
南方学院
专业:
计算机科学与技术
班级:
n1208011
姓名:
李晓雨
学号:
n120801107
实验1进程管理
1.实验目的
∙加深对进程概念的理解,明确进程和程序的区别。
∙进一步认识并发执行的实质。
∙分析进程争用资源的现象,学习解决进程互斥的方法。
∙了解Linux系统中进程通信的基本原理。
2.实验预备内容
(1)阅读Linux的sched.h源码文件,加深对进程管理概念的理解。
(2)阅读Linux的fork.c源码文件,分析进程的创建过程。
3.实验内容
(1)进程的创建
(2)编写一段程序,使用系统调用fork()创建两个子进程。
当此程序运行时,在系统中有一个父进程和两个子进程活动。
让没一个进程在屏幕上显示一个字符:
父进程显示字符“a”;子进程分别显示字符“b”和字符“c”。
试观察记录屏幕上的显示结果,并分析原因。
4.实验程序
#include
Main()
{
intp1,p2;
while((p1=fork())==-1);
if(p1==0)
putchar(‘b’)
else
{
while((p2=fork())==-1);
if(p2==0)
putchar(‘c’);
elseputchar(‘a’);
}
putchar(‘\n’);
}
5.实验结果
程序运行后出现bac、bca、abc等多种情况。
实验2进程间通信
一、实验目的
Linux系统的进程通信机构(IPC)允许在任意进程间大批量地交换数据。
本实验的目的是了解和熟悉Linux支持的消息通信机制、共享存储区机制及信息机制。
二、实验预备内容
阅读Linux系统的msg.c\sem.c等源码文件,熟悉Linux的三种通信机制。
三、实验内容
(1)消息的创建,发送和接收。
1.使用系统调用msgget(),msgsnd(),msgrev()j及msgctl()编制一长度1k的消息的发送和接收程序。
2.观察上面程序,说明控制消息队列系统msgctl()在此起什么作用?
3.实验程序
#include
#include
#include
#include
#include
#defineMSGKEY75
structmsgform
{longmytype;
charmtext[1030];
}msg;
intmsgqid,i;
voidCLENT()
{inti;
msgqid=msgget(MSGKEY,0777);
for(i=10;i>=1;i--)
{msg.mytype=i;
printf(“(client)sent\n”);
msgsnd(msgqid,&msg,1024,0);/*发送消息msg入msgqid消息队列*/
}
exit(0);
}
voidSERVER()
{msgqid=msgget(MSGKEY,0777LIPC_CREAT);/*由关键字获得消息队列*/
do
{msgrcv(msgqid,&msg,1030,0,0);/*从msgqid队列接受消息msg*/
printf(“(server)received\n”);
}while(msg.mytype!
=1);
msgctl(msgqid,IPC-RMID,0);/*消息队列为1时释放队列*/
Exit(0);
}
voidmain()
{while((i=fork())==-1);
if(!
i)SERVER();
while((i=fork())==-1;
if(!
i)CLIENT();
wait(0);
wait(0);
}
4、实验结果:
user@user-desktop:
~$gcc-0shiyan2shiyan2.c
user@user-desktop:
~$./shiyan2
(client)sent
(client)sent
(client)sent
(server)received
(server)received
(server)received
(client)sent
(client)sent
(server)received
(client)sent
(server)received
(client)sent
(server)received
(client)sent
(server)received
(client)sent
(server)received
(client)sent
(server)received
(server)received
user@user-desktop:
~$
实验3存储管理
1.实验目的:
存储管理的主要功能之一是合理地分配空间。
请求页式管理式一种常用的虚拟存储管理技术。
本实验的目的是通过请求页式存储管理中页面置换算法模拟设计,了解虚拟存储技术的特点,掌握请求页式存储管理的页面置换算法。
2.实验内容:
(1)通过随机数产生一个指令序列,共320条指令。
指令的地址按下述原则生成:
1.50%的指令是顺序执行的;
2.25%的指令是均匀分布在前地址部分;
3.25%的指令是均匀分布在后地址部分。
3.实验程序
#include
#defineTRUE1
#defineFALSE0
#defineINVALID-1
#defineNULL0
#definetotal_instruction320
#definetotal_vp32
#defineclear_period50
typedefstruct
{intpn,pfn,counter,time;
}
pl_type;
pl_typepl[total_vp];
structpfc_struct*next;
};
typedefstructpfc_structpfc_type;
Pfc_typepfc[total_vp],*freepf_head,*busypf_head,*busypf_tail;
intdisaffect,a[total_instruction],offset[total_instruction];
inttotal_pf;
voidinitialize(total_pf)
{inti;
disaffect=0;
for(i=0;i {pl[i].pn=I; pl[i].pfn=INVALID; pl[i].counter=0; pl[i].time=-1; } for(i=1;i {pfc[i-1].next=&pfc[i]; Pfc[i-1].pfn=i-1; } pfc[total_pf-1].next=NULL; pfc[total_pf-1].pfn=total_pf-1; freepf_head=&pfc[0]; } voidFIFO(total_pf) inttotal_pf; {intI,j; pfc_type*p,*t; initialize(total_pf); busypf_head=busypf_tail=NULL; for(i=0;total_instruction;i++) { if(pl[page[i]].pfn==INVALID) {disaffect+=1; If(freepf_head==NULL) {p=busypf_head->next; pl[busypf_head->pn].pfn=INVALID; freepf_head=busypf_head; freepf_head->next=NULL; busypf_head=p; } p=freepf_head->next; freepf_head->next=NULL; freepf_head->pn=page[i]; pl[page[i]].pfn=freepf_head->pfn; if(busypf_tail==NULL) busypf_head=busypf_tail=freepf_head; else{ busypf_tail->next=freepf_head; busypf_tail=freepf_head; } freepf_head=p; } } printf(“FIFO: %6.4f”,1-(float)diseffect/320); } voidLRU(total_pf) inttotal_pf; {intmin,minj,i,j,present_time; initialize(total_pf);present_time=0; for(i=0;i {if(pl[page[i]].pfn==INVALID) {diseffect++; if(freepf_head==NULL) {min=32767; for(j=0;j if(min>pl[j].time&&pl[j].pfn! =INVALID) {min=pl[j].time;minj=j;} freepf_head=&pfc[pl[minj].pfn]; pl[minj].pfn=INVALID; pl[minj].time=-1; freepf_head->next=NULL; } pl[page[i]].pfn=freepf_head->pfn; pl[page[i]].time=present_time; freepf_head=freepf_head->next;} else pl[page[i]].time=present_time; present_time++; } printf(“LRU: %6.4f”,1-(float)diseffect/320); } voidNUR(total_pf) inttotal_pf; {inti,j,dp,cont_flag,old_dp; pfc_type*t; initiallze(total_pf); dp=0; for(i=o;i {if(pl[page[i]].pnf==INVALID) {disaffect++; if(freep_head==NULL) {cont_flag=TURE;old_dp=dp; while(cont_flag) if(pl[dp].counter==0&&pl[dp].pfn! =INVALID) cont_flag=FALSE; else {dp++; if(dp==total_vp) dp=0; for(j=0;j pl[j].counter=0; } freepf_head=&pfc[pl[dp].pnf]; pl[dp].pnf=INVALD; freep_head->next=NULL); } pl[page[i]].pfn=freepf_head->pfn; freepf_head=freepf_head->next; }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 操作系统 实习