收藏 分销(赏)

Linux内核编译.doc

上传人:pc****0 文档编号:8734801 上传时间:2025-02-28 格式:DOC 页数:18 大小:538.50KB
下载 相关 举报
Linux内核编译.doc_第1页
第1页 / 共18页
Linux内核编译.doc_第2页
第2页 / 共18页
Linux内核编译.doc_第3页
第3页 / 共18页
Linux内核编译.doc_第4页
第4页 / 共18页
Linux内核编译.doc_第5页
第5页 / 共18页
点击查看更多>>
资源描述

1、操作系统课程设计实验报告册班级: 131112 学号: 13111xxx 姓名: xxxxxx 教师: 第 2 页 共 18 页目 录实验说明重要提示 实验2 makefile的编写及Linux内核编译 (8学时) 要求:掌握Linux中makefile文件的编写理解Linux内核的Makefile掌握至少一个版本Linux内核的编译步骤了解Linux内核的配置过程实验编号2题目makefile的编写及Linux内核编译实验目的掌握Linux中makefile文件的编写理解Linux内核的Makefile掌握至少一个版本Linux内核的编译步骤了解Linux内核的配置过程实验内容 准备工作 相

2、关软件的获取与安装(源代码,软件包) 编译工作 配置,编译 修改启动配置文件 修改grub2启动项 能够正确的编译源代码 能够用编译出的内核启动系统报告内容要求(1) 实现方法和思路(2) 测试及结果报 告 正 文内核编译过程内核原版本号:2.6.32-28-generic拷贝源代码到/usr/src目录下在usr/src目录下解压源码:拷贝packages到“”目录下:安装软件包:dpkg -i gcc-4.4_4.4.3-4ubuntu5.1_i386.deb;dpkg -i libgomp1_4.4.3-4ubuntu5.1_i386.deb;dpkg -i cpp-4.4_4.4.3-

3、4ubuntu5.1_i386.deb;dpkg -i xz-utils_4.999.9beta+20091116-1_i386.deb;dpkg -i patch_2.6-2ubuntu1_i386.deb;dpkg -i dpkg-dev_1.15.5.6ubuntu4.6_all.deb;dpkg -i fakeroot_1.14.4-1ubuntu1_i386.deb;dpkg -i gcc-4.4-base_4.4.3-4ubuntu5.1_i386.deb;dpkg -i libstdc+6_4.4.3-4ubuntu5.1_i386.deb;dpkg -i libgcc1_4.4

4、3-4ubuntu5.1_i386.deb;dpkg -i -force- g+-4.4_4.4.3-4ubuntu5.1_i386.deb ;dpkg -i libstdc+6-4.4-dev_4.4.3-4ubuntu5.1_i386.deb;dpkg -i g+_4.4.3-1ubuntu1_i386.deb;dpkg -i build-essential_11.4build1_i386.deb;dpkg -i cvs_1.12.13-12ubuntu1.10.04.1_i386.deb;dpkg -i gettext_0.17-8ubuntu3_i386.deb;dpkg -i in

5、tltool-debian_0.35.0+20060710.1_all.deb;dpkg -i po-debconf_1.0.16_all.deb;dpkg -i kernel-package_12.032_all.deb;dpkg -i libsys-hostname-long-perl_1.4-2_all.deb;dpkg -i libmail-sendmail-perl_0.79.16-1_all.deb;dpkg -i libncurses5-dev_5.7+20090803-2ubuntu3_i386.deb转到内核源代码所在的目录 “/usr/src/linux-2.6.32.60

6、输入Make menuconfig,进入general setup选项,进入local version菜单,添加版本标示:rain13111153,保存并退出。输入make语句,等待2小时make modules_installmake installupdate-initramfs c k 2.6.32.60rain13111153修改grub启动项:cd/boot/grubGedit grub.cfg重新启动ubuntu查看内核版本号:2.6.32.60rain13111153实验编号3题目Linux的进程和线程实验目的理解进程/线程的概念掌握创建和终止进程/线程的方法掌握与进程/线程控

7、制相关的系统函数实验内容创建和终止进程/线程使用进程/线程控制相关的系统函数报告内容要求(1) 实现方法和思路(2) 测试及结果报 告 正 文 getpid():获得当前进程ID getppid():获得当前进程的父进程的ID getuid():获得用户ID getgid():获得组ID源代码:#include #include #include int main()pid_t myPid;pid_t myParentPid;gid_t myGid;uid_t myUid; myPid = getpid();myParentPid = getppid();myGid = getgid();my

8、Uid = 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 %dn, myUid);return 0;运行结果;API函数用途fork创建一个新的子进程wait将进程挂起直到子进程退出signal注册一个新的信号句柄pause将进程挂起直到捕获到信号kill向某个指定的进程发出信号exit正常中止当前进程Wait函数pid = wait( &

9、status );If( WIFEXITED(status) ) printf(“Child exited normally with status %dn”, WEXITSTATUS(status);else if( WIFSIGNALED(status) ) printf(“Child exited by signal with status %dn”,WTERMSIG(status);源代码:#include #include #include int main()pid_t ret;int status , i;int role = -1;ret = fork();if(ret 0)p

10、rintf(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; elseif(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; elseprintf(Pa

11、rent: Error trying to fork() (%d)n, errno);printf(%s: Exiting.n, (role =0)?Parent:Child);return 0;运行结果:signal函数信号说明SIGHUP挂起SIGINT键盘中断SIGKILLKill信号SIGUSR1用户自定义信号SIGUSR2用户自定义信号SIGPIPE终止管道SIGTERM终止信号源代码:#include #include #include #include void catch_ctlc( int sig_num)printf(Caught Control-Cn);fflush(st

12、dout);/清除标准输出的缓存区int main()signal( SIGINT, catch_ctlc);printf(Go ahead, make my day.n);pause();return 0;运行结果: pause函数 pause函数会把进程挂起,直到接收到信号。在接收到以后,调用进程从pause中返回,继续进行。如果进程捕获的信号已经注册了信号句柄,那么pause函数会在信号句柄被调用并返回之后才返回。 pause原型: 头文件 int pause( void );pid说明0信号发送到由pid指定的进程0信号发送到与调用进程同组的所有进程-1信号发送到所有进程(init进程

13、除外)0信号发送到由pid的绝对值指定的进程组中的所有进程源代码:#include #include #include #include #include #include void usr1_handler( int sig_num)printf(Parent (%d) got the SIGUSR1n, 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() );sig

14、nal( SIGUSR1, usr1_handler);role = 0;pause();printf(Parent: Awaiting child exitn);ret = wait( &status); else if(ret = 0)printf(Child: This 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);elseprintf(Paren

15、t: Error trying to fork() (%d)n, errno);printf(%s: Exitingn, ( ( role = 0) ? Parent : Child);return 0;运行结果: exit函数 终止调用进程。传入exit的参数会返回给父进程,为wait或waitpid调用提供所需要的状态信息。 exit原型: void exit( int status); 进程调用exit时还会向父进程发出SIGCHLD信号,释放当前进程占用的资源。 这个函数调用十分重要,因为他会向Shell坏境表明状态时成功还是失败。 线程函数 头文件 创建线程原型 int pthrea

16、d_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void*), void *arg); 第一个参数为指向线程标示符的指针。 第二个参数用来设置线程属性。 第三个参数是线程运行函数的起始地址。 最后一个参数是运行函数的参数。 若成功则返回0,若失败则返回出错编号。 线程函数 终止线程原型 int pthread_exit(void *retval);源代码:#include #include #include #include #include void *myThread(void *arg)pr

17、intf(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 #include #include #include #include void *myThread(void *arg)printf(Thread

18、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!=1)printf(11111111n);exit(-1);return 0;运行结果: 线程管理 pthread_t pthread_self(void);/获得自己的线程描述符void *myThread(void

19、arg) pthread_t pt; pt = pthread_self(); printf(Thread %x ran!n, (int)pt); pthread_exit(NULL); int pthread_join(pthread_t th, void *thread_return ); 参数th是想要加入的线程 参数thread_return存储线程完成后的返回值,可以为NULL,表明不捕获线程的返回状态。 返回值,0代表成功,非0代表失败的编号。源代码;#include #include void *myThread(void *arg)printf(Thread %d start

20、edn, (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);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);elseprintf(Status = %dn, status);return 0;运行结果:实验编号4题目xxxxxxxxxxxxxxxxx实验目的实验内容报告内容要求(1) 实现方法和思路(2) 测试及结果报 告 正 文第 18 页 共 18 页

展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传
相似文档                                   自信AI助手自信AI助手
搜索标签

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服