00操作系统课内实验报告Word文档格式.docx
- 文档编号:6503514
- 上传时间:2023-05-06
- 格式:DOCX
- 页数:33
- 大小:298.47KB
00操作系统课内实验报告Word文档格式.docx
《00操作系统课内实验报告Word文档格式.docx》由会员分享,可在线阅读,更多相关《00操作系统课内实验报告Word文档格式.docx(33页珍藏版)》请在冰点文库上搜索。
{
echo–n"
Numberofmatchesfor$1:
"
#接收程序的第一个参数
ls$1|wc–l#对子程序的第一个参数所在的目录进行操作
}
(2)执行
将count文件复制到当前目录下,然后在当前目录下建立文件夹my:
mkdirmy
cdmy
vi1.c#在my目录下建立几个c文件,以便用来进行测试
...
cd...
chmod+xcount
count./my/*.c
Ø
2)系统调用实验
该实验是通过实验者对“Linux操作系统的系统调用机制”的进一步了解来理解操作系统调用的运行机制;
同时通过“自己创建一个系统调用mycall()”和“编程调用自己创建的系统调用”进一步掌握创建和调用系统调用的方法。
编程调用一个系统调用fork(),观察结果。
#include<
stdio.h>
intmain()
intiUid;
iUid=fork();
if(iUid==0)
for(;
;
){printf("
Thisisparent.\n"
);
sleep
(1);
}
if(iUid>
0)
){
printf("
Thisischild.\n"
sleep
(1);
}
if(iUid<
0)printf("
Cannotusesystemcall.\n"
return0;
}
结果:
实验中出现的问题
观察到的现象的解释和说明
实验体会
编程调用创建的系统调用foo(),观察结果。
#include<
linux/unistd.h>
_syscall1(char*,foo,int,ret)
main()
intI,J;
I=100;
J=0;
J=foo(I);
printf("
Thisistheresultofnewkernel\n"
%d"
j);
自己创建一个系统调用mycall(),实现功能:
显示字符串到屏幕上。
编程调用自己创建的系统调用。
syscall1(char*,mycall,int,ret)
intmain()
char*str;
charstring[50];
str=string;
str="
Thisstringwillbedisplayed."
mycall(str);
实验二:
进程管理实验
1)加深对进程概念的理解,明确进程和程序的区别。
2)进一步认识并发执行的实质。
3)分析进程争用资源的现象,学习解决进程互斥的方法。
4)了解Linux系统中进程通信的基本原理。
进程是操作系统中最重要的概念,贯穿始终,也是学习现代操作系统的关键。
通过本次实验,要求理解进程的实质和进程管理的机制。
在Linux系统下实现进程从创建到终止的全过程,从中体会进程的创建过程、父进程和子进程的关系、进程状态的变化、进程之间的同步机制、进程调度的原理和以信号和管道为代表的进程间通信方式的实现。
1)编制实现软中断通信的程序
使用系统调用fork()创建两个子进程,再用系统调用signal()让父进程捕捉键盘上发出的中断信号(即按delete键),当父进程接收到这两个软中断的某一个后,父进程用系统调用kill()向两个子进程分别发出整数值为16和17软中断信号,子进程获得对应软中断信号,然后分别输出下列信息后终止:
Childprocess1iskilledbyparent!
!
Childprocess2iskilledbyparent!
父进程调用wait()函数等待两个子进程终止后,输入以下信息,结束进程执行:
Parentprocessiskilled!
多运行几次编写的程序,简略分析出现不同结果的原因。
2)编制实现进程的管道通信的程序
使用系统调用pipe()建立一条管道线,两个子进程分别向管道写一句话:
Childprocess1issendingamessage!
Childprocess2issendingamessage!
而父进程则从管道中读出来自于两个子进程的信息,显示在屏幕上。
要求:
父进程先接收子进程P1发来的消息,然后再接收子进程P2发来的消息。
程序清单(含注释)
signal.h>
unistd.h>
sys/types.h>
intwait_flag;
voidstop();
main(){
intpid1,pid2;
//定义两个进程号变量
signal(3,stop);
//或者signal(14,stop);
while((pid1=fork())==-1);
//若创建子进程1不成功,则空循环
if(pid1>
0){//子进程创建成功,pid1为进程号
while((pid2=fork())==-1);
//创建子进程2
if(pid2>
0){
wait_flag=1;
sleep(5);
//父进程等待5秒
kill(pid1,16);
//杀死进程1
kill(pid2,17);
//杀死进程2
wait(0);
//等待第1个子进程1结束的信号
//等待第2个子进程2结束的信号
printf("
\nParentprocessiskilled!
\n"
exit(0);
//父进程结束
else{
wait_flag=1;
signal(17,stop);
//等待进程2被杀死的中断号17
\nChildprocess2iskilledbyparent!
exit(0);
else{
signal(16,stop);
//等待进程1被杀死的中断号16
\nChildprocess1iskilledbyparent!
voidstop(){
wait_flag=0;
实验结果
intpid1,pid2;
//定义两个进程变量
main(){
intfd[2];
charOutPipe[100],InPipe[100];
//定义两个字符数组
pipe(fd);
//创建管道
while((pid1=fork())==-1);
//如果进程1创建不成功,则空循环
if(pid1==0){//如果子进程1创建成功,pid1为进程号
lockf(fd[1],1,0);
//锁定管道
sprintf(OutPipe,"
\nChildprocess1issendingmessage!
//给Outpipe赋值
write(fd[1],OutPipe,50);
//向管道写入数据
sleep(5);
//等待读进程读出数据
lockf(fd[1],0,0);
//解除管道的锁定
//结束进程1
while((pid2=fork())==-1);
//若进程2创建不成功,则空循环
if(pid2==0){
\nChildprocess2issendingmessage!
wait(0);
//等待子进程1结束
read(fd[0],InPipe,50);
//从管道中读出数据
%s\n"
InPipe);
//显示读出的数据
//等待子进程2结束
read(fd[0],InPipe,50);
实验三存储器管理实验
1)理解内存页面调度的机理
2)掌握几种理论页面置换算法的实现方法
3)了解HASH数据结构的使用
4)通过实验比较几种调度算法的性能优劣
页面置换算法是虚拟存储管理实现的关键,通过本次实验理解内存页面调度的机制,在模拟实现FIFO、LRU、NRU和OPT几种经典页面置换算法的基础上,比较各种页面置换算法的效率及优缺点,从而了解虚拟存储实现的过程。
对比以下几种算法的命中率:
1)先进先出算法FIFO(FirstInFirstOut)
2)最近最少使用算法LRU(LeastRecentlyUsed)
3)最近未使用算法NUR(NeverUsedRecently)
4)最佳置换算法OPT(OptimalReplacement)
#include"
time.h"
iostream>
math.h"
stdlib.h"
#defineap3
#definepp5
#definetotal10
usingnamespacestd;
inttotal_instruction;
intdiseffect;
intpage[ap];
intpagecontrol[pp];
intmmn[total];
intpagecount;
voidmain()
intr1,flag;
inti,j,r,l,x;
intt,zai,m;
intk,temp;
doublemz;
for(i=0;
i<
ap;
i++)
{
page[i]=0;
for(j=0;
j<
pp;
j++)
pagecontrol[j]=0;
}
srand(time(NULL));
for(k=0;
k<
total;
k++)
{
inttemp=rand()%6;
mmn[k]=temp;
cout<
<
mmn[k];
cout<
endl;
total_instruction=0;
diseffect=0;
"
thefirstthreepagesare:
for(r=0;
r<
r++)
zai=mmn[r];
page[r]=zai;
pagecontrol[zai]=1;
page[r];
total_instruction++;
diseffect++;
endl<
for(t=ap;
t<
t++)
flag=1;
for(l=0;
l<
l++)
{
if(page[l]==mmn[t])
{
total_instruction++;
cout<
onepagematched"
flag=0;
if(flag!
=0){
onepagenotmatched"
m=page[0];
for(i=0;
ap-1;
page[i]=page[i+1];
r1=mmn[t];
page[ap-1]=r1;
pagecontrol[m]=0;
pagecontrol[r1]=1;
for(x=0;
x<
3;
x++){
page[x];
}cout<
diseffectis"
diseffect<
total_instructionis"
total_instruction<
mz=(double)diseffect/(double)total_instruction;
mzis"
(1.000-mz)<
(1)使用指导书上所给的数字串:
(2)随机生成数字串:
intmmn[total]={1,4,2,5,3,3,2,4,2,5};
intr1,gr,flag;
inti,j,r,l,h,x;
intt,zai,m,li;
//srand(time(NULL));
//inttemp=rand()%6;
//mmn[k]=temp;
total_instruction=total;
if(page[l]!
=page[ap-1])
{
gr=page[l];
for(li=l;
li<
li++)
{
page[li]=page[li+1];
}
page[ap-1]=gr;
if(flag!
onepagenotmatched!
x++)
cout<
(1)使用指导书上给的数字串:
(2)随机生成数字串
iostream"
#defineclear_period5
intperiod;
intr1,flag,find;
inti,j,r,l,x,s;
intt,zai,m,la,f;
intk,temp,ten;
//inttemp=rand()%6;
//mmn[k]=temp;
period++;
if((period%clear_period)==0)
for(s=0;
s<
s++)
pagecontrol[s]=0;
total_instruction++;
la=page[l];
pagecontrol[la]++;
period++;
if(flag!
period++;
find=0;
for(m=0;
m<
m++)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 00 操作系统 实验 报告