操作系统课程_上机报告_第1页
操作系统课程_上机报告_第2页
操作系统课程_上机报告_第3页
操作系统课程_上机报告_第4页
操作系统课程_上机报告_第5页
已阅读5页,还剩24页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、操作系统课程设计实验报告册实验说明本课程由操作系统实验和操作系统课程设计专题两部分组 成,共计56学时,分7次实施,每次8学时。本课程使用linux系统为实验平台,推荐使用ubuntu 10. 04/内核版本2. 6. 32-28/源码版本2. 6. 32-60;重要提示实验1linux (虚拟机)安装及linux常用命令使用实验2makefile的编写及linux内核编译实验3linux的进程和线程实验4同步与互斥实验5文件系统实验说明1. 实验做为学习的重要促进手段,是为了深化对理论的理解,锻炼实践动 手能力。2. 实验同时也作为考核的手段。3. 实验内容会在课程进行中下达,并且会分次地、

2、部分地被抽查。4. 课程结束时,要求把所有的实验整理成一个完整的电子文档并上交,做 为最后成绩的评定依据。5. 如果有兴趣的合适的题目,也可自己选题目。格式说明1. 本文档文件名命名为“学号-姓名”,如“13071000_小王”。2. 留白部分不足的自己调整长度,也可加页(增加内容应在表格内)。3. 每次的实验报告都要在这个文件中(按照实验次序依次)增加,而不是 每次一个新的word文件。4. 本文档保存为doc格式(请勿用word2007的docx格式)。重要提示:1. 实验正文建议使用小四号或五号宋体。2. 若附加图形,则请直接嵌入到实验手册相应位置。3. 各实验的源程序,请按实验分目录存

3、放,如第一个实验的源程序存放在 目录iab1下,第二个实验的源程序存放在目录iab2下等等,依次类推。4. 可互相讨论,但严禁抄袭网络或同学的实验结果。实验编号 1 题目 linux (虚拟机)安装及linux常用命令使用掌握至少一种linux系统的安装1、掌握虚拟机平台(vmware workstation)的使用和配置实验目的2、掌握至少一种配置vmware中linux系统与宿主机windows系统的 文件交换的方法3、掌握常用的linux命令4、了解linux的帮助系统实验 1、安装vmware虚拟机内容 2、在虚拟机上安装linux系统,安装vmware tools告容求报内耍(1)

4、实现方法和思路:按照安装手册安装虚拟机,在虚拟机上安装系 统,了解linux指令组成,练习linux常用指令(2) 测试及结果:试验成功报告正文女装linux成功这一发行版w ubuntu 10目有里程碑式的层必 牧以百计的改逬便它比以柱的炬本更易用、更可il迟些改逬包括 新的视般编直齢m成的社交网络功能和bdt仍在不断増长nwun%件蔑芻.我们相信,无论您是第一次©il ubuntu的新用户,还是疑疲车富的长阴用户.邵会发理倉牙喜欢的东西.在安餐逍 行蹈.我们違谒您通过i2tfl«n片一起采根嚴iubuntu ift计的于便用.一起来自由地撮吧linux help 命令应

5、用程序 宜 糸比 r !匸$丄丄用巧口圭期匕i卜十世囲 ? 邓 mqtwvj 0 g gyxubuntu: 文件(f)编辑(e)查看(v)终端仃)帮助(h) gyxubuntu:*$ helppwdhpwd: pwd -lpiprint the nameof the current working directory.ioptions:ilprintthe value of $pwd if itnames the current workingidirectoryipprintthe physical directory,without any symbolic linksiby defaul

6、t,'pwd1behaves as if -l1 werespecified.iexit status:ireturns 0 unless an invalid option is given or the current directory i cannot be read.igyxubuntu:$ |i目录操作命令:cd命令:彳应用程序位畫系统“ 11月9日星期日下午4:30圏* 0 o o gyxubuntu: /os文件(f)编辑(e)查看(v)终端仃)帮助(h)gyxubuntu:-$ isbexam叽es. desktop ubuntuone公共的 文档模板音乐hostft

7、囹片 桌面视频igyxubuntu:$ pwdh/home/gyxhgyxubuntu:$ cd /homehgyxubuntu:/home$ cd ./gyx/hgyxubuntu:*$ cd ./os/hgyxubuntu:/os$ ishlinux-2.63260tarbz2packages proigyx(aubuntu:/os$ |h头验编亏 2 题目 makefile的编写及linux内核编译实验 目的1、掌握linux中makefile文件的编写2理解linux内核的makefile3、掌握至少一个版本linux内核的编译步骤4、了解linux内核的配置过程实验内容编译 linu

8、x-2. 6. 32. 60. tar. bz2告容求报内要(1) 实现方法和思路准备丁作相关软件的获取与安装(源代码,软件包) 编译工作配置,编译修改启动配置文件修改grub2启动项(2) 测试及结果:成功报告正文配置make过程:applicationssystm y 卞t< 1' <i q r 10h ?« < 10 q wsy 0vmw*relm$96.0- )2x478 tar q/0 root 4wty-4etktop fvtr/mc/1lm4i*2 t.12 m ale edit yiew rntrwtf hhpis above array b

9、ound%4rlwrt/m/c»c«/vrt.o drlvrrs/irtb/cre/brsme. o & wr »/m>/cer«/ir avwr driwrwirtb/cre/coafig.oerr*ccwcc(hi10ccwcc(«1cc(«)cc(n110w10cc(h)cc(hiccw(x(hicccccctfriwrvutb/atvuimta.« 4r&ver$/irtb/atv«usteta driwrwmb/e«7bee/tuilt*iii.« dfivers

10、/mb/ct/bm/cejiw drv.o drive rs/irt>/c<7km/ce7i«-uftpi.e drivcrs/mb/cenee/cofiw hc< o drivcr$/mb/c4?im/ct7rte-scm 上 driwrs/mb/cttiee/cerm.o drtv«rs/irtb/cus$/bvilt ui.e driwr$/»b/cla$/cc*acb.o drive rs/ihb/rtms/v5bl.« dr ivers/mb/class/cdc -mdb .o driwrt/uso/class/mtac.o

11、driv<r$/v$b/corc/u$d.o driwrs/wtb/eere/hvb.o drlv«r$/mb/core/hcd.odrivert/utb/ctre/hcd.c: in faction 冷 string': /usr/src/llftui 2.».3212.h:m: warnini: «rr«y sul scriptcc cc cc cc更改设置:t>应用程序位置系统m 11月9日星期日下午4:39圏 * 4> m ggyx o己£纽巳 *grub.cfg (/boot/grub) gedit文件(f)

12、编辑(e)查看(v)搜索(s)工具(t)文档(d)帮助(h)i 2 打开 2保存超条橄消q 9epl *grub.cfg xihht cnu /clc/yi uu.u/vj ucu丄uh liiciiic ihht# begin /etc/grub.d/10 linux #menuenty ubuntu, with linux 0gyxf -class ubuntu -class gnu linux -class gnu 八class os recordfailinsmod ext2set root='(hdol) :、search -no-floppy -fs-uui

13、d -set 95ed7954-8c25-4aac-95b3- a8162434d7b8linux/boot/vmlinuz-0gyxroot=uuid=95ed7954-8c25-4aac-95b3-a8162434d7b8 ro quiet splashinitrd /boot/initrd. img-0gyx|4menuenty 'ubuntuf with linux 26.3228generic1 -class ubuntu class gnu-linux class gnu class os v1k纯文本 跳格宽度:8 行70方|插(3 roo

14、tubu. 0 rootubu.言*grub.cfg 脇 抓图重启后成功:< 应用程序 位置 系统勁? 口 11月9日星期日上午10:30叠 *3 0 0 gyxubuntu: 文件(f)编辑(e)查看(v)终端仃)帮助(h)gyxubuntu:-$ uname 厂0gyxgyxubuntu:$rootubuntu: /usr/src/qigyx o gyx.遐tgyxu©: 尸ro linux-0/arch/x86/kemel实验编号题el进程与线程实验目的熟悉进程和线程的基本操作并r代码实现实验内容自己敲岀代码并把实验结杲告容求报内要(1)

15、实现方法和思路:所有代码要自己敲写并测试并截图。示例4程序运行过程及结果分析,需画图分析父子进程的运行先后关系。(2) 测试及结果:截图显示结果报告正文c 跳格宽度:8 行19,列1插入示例2<5曲 tem2.c (*/mf'pro/thre<) gedit文弁(f)任)v) ik: xm(t)文©d) «b(h)temjc kc v imws 8 v h21. r28mapld t ret; bit iil«t role 梟 ret forko; lffrec > ><p<1m口ims t"m>r ye

16、tpldo):for(w:a<t;lw|<printf(*r«retit. at cewm wxn*. 1);sleep(l);> el -仙ll.role;>im if(rvt x*<printf<aoiiu: thz the child ”(的9etpid(>);<prlmf(*(mle: at count wn&):"ed”> rou 1;»im(printfcmr«it: trr«r trying re f»rt()(y)vr. "e>)printf

17、(em: “hlgrr. (role”广:(机2”;rtferr : (0 护cfcuntu f/mqmq gy)t3bur<u:口示例3d应用程序 位置 系统till月9日星期日下午5:15圏ra qgyx otem3.c (/os/pro/three) gedit文件(f)编辑(e)查看(v)打开込保存 超 、,同消tem3.c x#include <stdio.h>#inelude <sys/types.h>#inelude <signal.h>#inelude vunistd.h void catch_ctlc( int sig_num)pri

18、ntf(''caught control-cxn11);fflush (stdout); /清除标准输出的缓存区int main()signal( sigint, catch ctlc); printf(hgo aheadt make my dayanm); pauseo;return 0;c 跳相宽度:8 行15.列1插入: 0 gyxubu. 0 gyxubu. e tem3.c ( 购 抓图t应用程序位置系统?】1月9日星期日下午5:16圏* 如qgyx 0文件(f)编辑(e)查看(v)终端仃)帮助(h) gyxubuntu:-/os/pro/three$ ./tem3

19、|go ahead, make my day.accaught control-c gyxubuntu:-/os/pro/three$ 0 gyxubu 目 gyxubu.e tem3.c(.购抓图示例4文件:/home/gyx/o5/pro/three/tem4.c#inclixle <stdio.h, include <sys/types h, include <sys/wait.h> include <unistd.h> include <signal.h> include <errno.h>voidusrl tiandler(

20、 int sig numprintf ("parent (%d) got the sigusrlaft, getpidf);main()pid_t ret:irrt status;int role = -1ret = fork();if( ret > 0)intprintf("parent: this is the parent process (pid mlxn'getpido ); signal! sigvsrlt usrl handler):role = e;paused;printf('parent: awaiting child exitnh

21、); ret = wait( &status); else1 elseif(ret = 0)return 9;printf( 'child: this is the child process (pidgetpido);role = 1;sleep(l); printf(uchild: sending sigvsr1 to pid %dnm, getppido);kill (getppid()t sigu5a1h sleep(2;printf("parent: error trying to forklierrno);printf(u%s: exitingn ( (

22、role = 6) ? ”parent” : “child”;实例5#include #include #inelude #include #include<pthread.h> <stdlib.h> <stdio.h> <string.h> <erno.h> void mmythread(void *arg) printf("thread rannm); pthread exit(arg); int main()int ret;pthreadt mythread;ret = pthread create( &myt

23、hreadr null, mythread, null); if(ret != 0)printf(hcan not create pthread (%s)nj strerror(errno); exit(-l);for(ret=0;ret<10;ret+)printf(hthis is father nw);sleep(1);return 0;示例6<5 刨at亠 temft.c (-/m/pronhrea) geditxwfiv) (5)工jut) xi*o) (刖(emec k finclu4eiinclve <itdao.k»void fttumg"

24、 ”g)<printfcnrfm m(lutlary):pthfccd «xit<«rg);)define max thiua05 si»t mini)<int ret. 1. status;pthread t thre«dt<k>ux two; ford ; i<mx mum; 1) ret pthread <fedte(mme>aie$|lh «uu oythrem. (”")"; if(rvt lb )(prmtf(efrrer cfmtii "d wne. &

25、lt;voi4«)|);urd ; i<mx tmaos;ret pthreed )«in(thrc«dld$|i|. (wi4 if(rwt l« )(pfintfcrrmf |(m站y mreetf idw. (voitf >!); )(printr(*$fmu9 ww. ttatirt):ret«r« :fflmhmbi:匕 wetma示例7include <pthread.h>#inelude <stdio.h>#include <assert.h>pthread mutex t

26、 entr mutex = pthread mutex initializer; long protvariable = 0l;void *mythread(void *arg)int i, ret;for(i=0; i<10000; i+)ret = pthreadjnutex_lock( &cntrjnutex ); assert( ret = 0 );protvariable+;ret = pthread mutex unlock( &entr mutex ); assert( ret = 0 );pthread exit(null); 一#define max t

27、hreads 10int main()int retf i;pthread t threadldsmax threads;for(i=0? i<max threads;"i+) 一ret = pthread create( &threadldsif nullf mythread, null);if(ret != 0) printf (,ferror creating thread %dn"r (int)threadlds(i);for(i = 0; i<max threads; i卄) _ret = pthread join( threadldsit n

28、ull):if(ret != 8)printf("error joining thread %dn"f (int)threadlds(i); printf(mthe protected variable value is %ldnuf protvariable);ret = pthread mutex destroy( & cntr mutex );if(ret != 0 )printf("could not destroy the utexn");return 0;8 0 0 gyxubuntu: */os/pro/three文件(f)编辑(e

29、)查看(v)终请(t)帮助(h)thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9thisispthread9rhe protected vari

30、able value is 100000yxubuntu:*/os/pro/three$ 目实验编号4题目同步与互斥实验 目的理解并发中的互斥原理。具体到这次实验课,理解peterson算法蠶必做:实现peterson算法。利用peterson算法的原理,实现“生产者消费者模型”报告 内容 要求(1) 实现方法和思路:对关键区的访问控制。 多个生产者,一个消费者,一个缓存区。进程框架结构:生产者与消费者进去关键去吋要进行pv操作,查看是否有别的进程在进行操 作。并且查看缓存区有无数据。(2) 测试及结果:结果见截图报告止文程序:#include<pthread h>#include

31、<stdlib.h> #include<stdio.h> #include<unistd h> #include<semaphore h> #include<sys/typesh>#include<tiine h>#define number 3void producer_pthread(void *arg);void consumerpthreadcvoid *arg);pthread jnutex t- w mutex;int buff;int sem;int main()int res;int i;pthread t

32、 threadnumber+l; pthread mutex_lock(&w mutex); res-pthread create(&(threadlnumber),null,consumer pthread,(voide)number); if(0!-res)printf("create %i errorn"fnumber);exit(2);elseprintf(hcreate %i nmfnumber);for( i»0; i<number; i>+)/res=pthread mutex init(&(threadli).n

33、ull);if(0!=res)printf("init %d errornwfi);exit(l);/res=pthread_create(&(threadi) fnulltproducer_pthreadf (void *)i); if(8!»res)printf("create %i errorni); exit(2); elseprintf("createjrintfc*n-);buff-o;sem-o;pthread mutex unlock(&w mutex);for(res-0;l;res*) printfcres is mn

34、btr«s); sleep(l);return 0;void producer pthread(void arg)int result; while(l) result-pthread mutex trylock(&忖 butex); if(0!-result)printf("thread %d can*t lock buffn*t(int )arg);elseprintfc thread sd lock buffn t(int )arg);if (3=se) buff«(iat b)arg; se««l;prlntfcwrite re

35、cord to buffn ); sleep(l);elseprintfcbuff isprintf(apthread 5 :buff is going to be unlockedn jint s)arg); pthredd autex unlogd nutex);srand(tibe(null);sleep(rand()416);void conswer pthread(void arg)int result; while(l)result»ptbread nutex trylock(&m mutex); if(e?«result)'printf(* t

36、hread %d can't lock buffn*t(int *)arg);else printf( thread %d lock buffn(int w)arg);<se»«o;printf( read froa buff: mln*9buff);elseprintf(buff is enptyn );printfcpthread %d :buff is going to be unlockedn*f(int e)arg); pthread autex unlock(&w nutex);sleep(l);>gyx(aubuntu:/os/pr

37、o/four$ ./pthread create 3 create 0create 1create 2res is 0thread 2 lock buff write record to buff thread 1 can't lock buff thread 0 canft lock buff thread 3 can't lock buff res is 1pthread 2 :buff is going thread 3 lock buffread from buff: 2 pthread 3 :buff is going res is 2thread 3 lock bu

38、ff buff is empty pthread 3 :buff is going res is 3thread 3 lock buff buff is empty pthread 3 :buff is going res is 4thread 3 lock buff buff is empty pthread 3 :buff is going thread 1 lock buff write record to buff thread 0 can't lock buff res is 5thread 3 can't lock buff pthread 1 :buff is g

39、oing thread 1 lock buff buff is fullto be unlockedto be unlockedto be unlockedto be unlockedto be unlockedto be unlocked实验编号5题目文件系统实验 目的掌握锁的结构和操作掌握如何对文件进行加锁、解锁学会如何协调不同进程对同一文件的互斥操作实验 内容必做:文件锁的测试 选做:获取文件的状态信息 创建一个带有空洞的文件 掌握lseek函数的用法报告 内容 要求(1)实现方法和思路:文件的数据保护。在有多个进程并发执行的情况下,若多个进程同吋对同一文件进行写操作,则 会导致最后一个

40、进程的执行结果覆盖了以前进程所作的修改,从而产生非预期 结果。在linux系统中,fcntl函数向用户提供了对文件加锁、解锁以保证对 同一文件或文件内的某一区域的互斥操作。这取决于锁的设定。进程框架结构:打开一个新文件,再创建一个子进程。父子进程通过fcnt 1函 数进行文件级的加锁,来进行对该文件互斥的访问。(2)测试及结果:结果见截图报告正文必做题:文件锁测试 源程序:#include<stdio.h> il?include<sys/typs h> #include<fcntl.h> #include<unistd.h> #include&l

41、t;timeh #define size 5int nain()v int fd;pid t pid; struct flock lock: int start byte; int res;if(fd«open( file 0 rdwr)<6)printf(*open or creat file errorn*); exit(l); pid»fork();prlntfccan t forkn*);exit(2);lf(opid)printf(*child : %d n9etpido); for(start byte« ;start byte<190;s

42、tart byte*«size) <rarxktijk(null);sleep(rand()%5);lock.i whenceseek set;lock.l start*start byte;lock.ljen=5ize;"lock.i pid=-l; if(rand()v)lock.i type wrlck; printfj cild :r/ to wrloc : to s n ,startbyte,start bytesize); res=fcntl(fd,f setlkr&lock);if (-i=res)printf('child wrlock

43、 fail n-);prlntf( child:wrlock succeed ne);lock.i type=f rdlck; pnntfpchild :try to rdlock res=fcntl(fdrf setlkr&lock); if (-l=res)<printfcchild rdlock) else<printf( child rdlocksd to d r ,start byte,start bytesize);fail ne);succeed ne);ilseprintf( father : 5 ngetpid<); for(start byte«o;st«rt byte<10o;start byte*»size) rand(tibe(null);sleep(randlock l_wherke=seek set;lock lstartstartbyte;lock.riensize; lock.lpid-1;if(rand()%2) locka type»f mrlck;printf(*fve

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论