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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

超详细西电软院操作系统实验报告DOC.docx

1、超详细西电软院操作系统实验报告DOC操作系统课程设计实验报告册班级:1313012学号:.姓名:lan教师:杜军朝 实验1 Linux(虚拟机)安装及Linux常用命令使用 实验2 makefile的编写及Linux内核编译 实验3 Linux的进程和线程 实验4 同步与互斥 实验5 文件系统 重要提示:1 实验正文建议使用小四号或五号宋体。2 若附加图形,则请直接嵌入到实验手册相应位置。3 各实验的源程序,请按实验分目录存放,如第一个实验的源程序存放在目录lab1下,第二个实验的源程序存放在目录lab2下等等,依次类推。4 可互相讨论,但严禁抄袭网络或同学的实验结果。实验编号1题目Linux

2、(虚拟机)安装及Linux常用命令使用实验目的1、掌握至少一种Linux系统的安装2、掌握虚拟机平台(Vmware Workstation)的使用和配置3、掌握至少一种配置Vmware中Linux系统与宿主机Windows系统的文件交换的方法4、掌握常用的Linux命令5、了解Linux的帮助系统实验内容1、Linux(虚拟机)安装及Linux常用命令使用报 告 正 文1、目录操作命令2、文件操作命令3、文本文件查看命令4、用户系统命令5、网络相关命令6、U盘的使用方法7、用户管理命令8、用户组账号管理9、文件权限设置10、设置文件属主和属组实验编号2题目makefile的编写及Linux内核

3、编译实验目的1、掌握Linux中makefile文件的编写2、理解Linux内核的Makefile3、掌握至少一个版本Linux内核的编译步骤4、了解Linux内核的配置过程实验内容1、准备工作:相关软件的获取与安装(源代码,软件包)2、编译工作:配置,编译3、修改启动配置文件:修改grub2启动项4、能够正确的编译源代码5、能够用编译出的内核启动系统报告内容要求(1) 实现方法和思路(2) 测试及结果报 告 正 文内核编译过程1、拷贝源代码到/usr/src目录下将文件添加共享文件夹中,然后在terminal输入以下命令:cd /mnt/hgfscp -r packages /usr/src

4、cp linux-2.6.32.60 /usr/src2、在usr/src目录下解压源码:cd /usr/srctar xvf linux-2.6.32.60.tar.bz23、拷贝packages到“”目录下:cd /usr/srccp -r packages 4、安装软件包:dpkg i *.deb5、转到内核源代码所在的目录 “/usr/src/linux-2.6.32.60”:cd /usr/src/linux-2.6.32.606、输入make menuconfig,进入general setup选项,进入local version菜单,添加版本标示:lan,保存并退出。7、输入ma

5、ke语句,等待2小时8、make modules_install9、make install10、update-initramfs -c -k 2.6.32.60lan11、修改grub启动项:cd /boot/grub12、重新启动ubuntu13、查看内核版本号:实验编号3题目Linux的进程和线程实验目的1、理解进程/线程的概念2、掌握创建和终止进程/线程的方法3、掌握与进程/线程控制相关的系统函数实验内容1、创建和终止进程/线程2、使用进程/线程控制相关的系统函数报告内容要求(1) 实现方法和思路(2) 测试及结果报 告 正 文示例1源代码:#include #include #inc

6、lude int main() pid_t myPid; pid_t myParentPid; gid_t myGid; uid_t myUid; myPid = getpid(); myParentPid = getppid(); myGid = getgid(); myUid = getuid(); printf(my process id is %dn, myPid); printf(my parent is process id is %dn, myParentPid); printf(my group id is %dn, myGid); printf(my user id is %

7、dn, myUid); return 0;运行结果:示例2源代码:#include #include #include int main() pid_t ret; int status , i; int role = -1; ret = fork(); if(ret 0) printf(Parent: This the parent process (pid %d)n, getpid(); for(i=0;i6;i+) printf(Parent: At count %dn, i); sleep(3); ret = wait(&status);/防止僵尸进程的产生 role=0; else i

8、f(ret =0) printf(Child: This the child process (pid %d)n, getpid(); for(i=0;i6;i+) printf(Chile: At count %dn,i); sleep(1); role = 1; else printf(Parent: Error trying to fork() (%d)n, errno); printf(%s: Exiting.n, (role =0)?Parent:Child); return 0;运行结果:示例3源代码:#include #include #include #include void

9、 catch_ctlc( int sig_num) printf(Caught Control-Cn); fflush(stdout);/清除标准输出的缓存区int main() signal( SIGINT, catch_ctlc); printf(Go ahead, make my day.n); pause(); return 0;运行结果:示例4源代码:#include #include #include #include #include #include void usr1_handler( int sig_num) printf(Parent (%d) got the SIGUS

10、R1n, getpid() );int main() pid_t ret; int status; int role = -1; ret = fork(); if( ret 0) printf(Parent: This is the parent process (pid %d)n,getpid() ); signal( SIGUSR1, usr1_handler); role = 0; pause(); printf(Parent: Awaiting child exitn); ret = wait( &status); else if(ret = 0) printf(Child: This

11、 is the child process (pid %d)n, getpid(); role = 1; sleep(1); printf(Child: Sending SIGUSR1 to pid %dn, getppid(); kill(getppid(), SIGUSR1); sleep(2); else printf(Parent: Error trying to fork() (%d)n, errno); printf(%s: Exitingn, ( ( role = 0) ? Parent : Child); return 0;运行结果:示例5源代码:#include #inclu

12、de #include #include #include void *myThread(void *arg) printf(Thread rann); pthread_exit(arg);int main() int ret; pthread_t mythread; ret = pthread_create(&mythread,NULL,myThread,NULL); if(ret!=0) printf(Can not create pthread (%s)n,strerror(errno); exit(-1); return 0;运行结果:程序无输出内容改写程序如下:#include #i

13、nclude #include #include #include void *myThread(void *arg) printf(Thread rann); pthread_exit(arg);int main() int ret; pthread_t mythread; ret = pthread_create(&mythread,NULL,myThread,NULL); if(ret!=0) printf(Can not create pthread (%s)n,strerror(errno); exit(-1); if(ret=0) printf(Can create pthread

14、!n); return 0;运行结果:示例6源代码:#include #include void *myThread(void *arg) printf(Thread %d startedn, (int)arg); pthread_exit(arg);#define MAX_THREADS 5int main() int ret, i, status; pthread_t threadIdsMAX_THREADS; for(i = 0; iMAX_THREADS; i+) ret = pthread_create(&threadIdsi, NULL, myThread, (void*)i);

15、if(ret != 0) printf(Error creating thread %dn, (void*)i); for(i = 0; iMAX_THREADS; i+) ret = pthread_join(threadIdsi, (void *)&status); if(ret != 0) printf(Error joining thread %dn, (void *)i); else printf(Status = %dn, status); return 0;运行结果:示例7源代码:#include #include #include pthread_mutex_t cntr_mu

16、tex = PTHREAD_MUTEX_INITIALIZER;long protVariable = 0L;void *myThread(void *arg) int i, ret; for(i=0; i10000; i+) ret = pthread_mutex_lock( &cntr_mutex ); assert( ret = 0 ); protVariable+; ret = pthread_mutex_unlock( &cntr_mutex ); assert( ret = 0 ); pthread_exit(NULL);#define MAX_THREADS 10int main

17、() int ret, i; pthread_t threadIdsMAX_THREADS; for(i=0; iMAX_THREADS; i+) ret = pthread_create( &threadIdsi, NULL, myThread, NULL); if(ret != 0) printf(Error creating thread %dn, (int)threadIdsi); for(i = 0; iMAX_THREADS; i+) ret = pthread_join( threadIdsi, NULL); if(ret != 0) printf(Error joining t

18、hread %dn, (int)threadIdsi); printf(The protected variable value is %ldn, protVariable); ret = pthread_mutex_destroy( & cntr_mutex ); if(ret != 0 ) printf(Could not destroy the mutexn); return 0;运行结果:实验编号4题目同步与互斥实验目的1. 学习理解并发中的互斥原理2. 掌握peterson算法的原理及实现方法 3. 实现生产者消费者模型 实验内容1.实现Peterson算法;理解互斥的概念2.利用P

19、eterson算法的原理;实现“生产者消费者”程序,理解同步互斥的概念报告内容要求(1) 实现方法和思路(2) 测试及结果报 告 正 文一、Peterson算法 本实验利用软件方法实现同步互斥,也就是通过peterson算法,不通过中断等物理机制实现同步互斥。 Peterson算法特点:使用两个全局变量(flag和turn),flag表示哪个进程正在占用临界区及临界区的状态,turn表示能进入临界区的进程序号。此算法涉及两个原则:忙则等待,空闲让进。源代码:#include#include#include#include#define false 0#define true 1int flag

20、2;int turn=0;int s=0;void *P0(void *arg);void *P1(void *arg);int main() pthread_t pt0, pt1; flag0=false; flag1=false; pthread_create(&pt0,NULL,P0,NULL); pthread_create(&pt1,NULL,P1,NULL); pthread_join(pt0,NULL); pthread_join(pt1,NULL); return 0;void *P0(void *arg) while(true) flag0=true; turn=1; whi

21、le(flag1&turn=1) continue; printf(I am process 0 and I got s:%dn,s); s+; flag0=false; sleep(1); void *P1(void *arg) while(true) flag1=true; turn=0; while(flag0&turn=0) continue; printf(I am process 1 and I got s:%dn,s); s+; flag1=false; sleep(1); 运行结果:2、用Peterson算法实现“生产者消费者”程序源代码:#include #include #

22、define MAX 10 /需要生产的数量pthread_mutex_t the_mutex;pthread_cond_t condc, condp;int buffer = 0;/生产者、消费者使用的缓冲区void *producer(void *ptr) int i; for(i=1; i=MAX; i+) pthread_mutex_lock(&the_mutex); /互斥使用缓冲区 while(buffer !=0) pthread_cond_wait(&condp, &the_mutex); printf(procucer produce item %dn,i); buffer

23、= i; /将数据插入缓冲区 pthread_cond_signal(&condc);/唤醒消费者 pthread_mutex_unlock(&the_mutex);/释放缓冲区 pthread_exit(0);void *consumer(void *ptr) int i; for(i=1; i=MAX; i+) pthread_mutex_lock(&the_mutex);/互斥使用缓冲区 while(buffer =0) pthread_cond_wait(&condc, &the_mutex); printf(consumer consume item %dn,i); buffer =

24、 0;/从缓冲区中取出数据 pthread_cond_signal(&condp);/唤醒生产者 pthread_mutex_unlock(&the_mutex);/释放缓冲区 pthread_exit(0);int main(int argc, char *argv) pthread_t pro, con; pthread_mutex_init(&the_mutex, 0); pthread_cond_init(&condc,0); pthread_cond_init(&condp,0); pthread_create(&con, 0, consumer, 0); pthread_creat

25、e(&pro, 0, producer, 0); pthread_join(pro,0); pthread_join(con,0); pthread_cond_destroy(&condc); pthread_cond_destroy(&condp); pthread_mutex_destroy(&the_mutex); return 0; 运行结果:实验编号5题目文件系统实验目的1. 掌握锁的结构和操作 2. 掌握如何对文件进行加锁,解锁 3. 学会如何协调不同进程对同一文件的互斥操作实验内容1. 文件锁的测试 以下选做: 2. 获取文件的状态信息 3. 创建一个带有空洞的文件 4. 掌握l

26、seek函数的用法报告内容要求(1) 实现方法和思路(2) 测试及结果报 告 正 文1、文件锁的测试#include #include #include #include #include #include int main() int fd; pid_t pid; struct flock rdlock,wrlock; rdlock.l_type = F_RDLCK; rdlock.l_start = 0; /读锁 rdlock.l_whence = SEEK_SET; rdlock.l_len = 0; wrlock.l_type = F_WRLCK; wrlock.l_start = 0; /写锁 wrlock.l_whence = SEEK_SET; wrlock.l_len = 0; if(fd = open(myfile,O_RDWR) 0) printf(cannot open the filen); exit(EXIT_FAILURE); if(write(fd,abcdefgh,8)

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

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