重庆邮电大学移通学院毕业设计(论文)
重庆邮电大学移通学院毕业设计(论文)任务书
设计(论文)题目 Linux多进程编程及应用 学生姓名 *** 系别 计算机专业计算机科学与技术班级 ********
指导教师 ** 职称 讲师 联系电话 ******* 指导教师所在单位 重庆邮电大学移通学院计算机系
主 要 研 究 内 容 、 方 法 和 要 求 进 度 计 划 主 要 参 考 文 献 要求:熟悉Linux内核进程相关代码,熟悉Linux多进程编程。 内容: 1、掌握Linux内核进程相关代码。 2、掌握Linux进程的静态结构。 3、熟悉Linux进程的创建,调度,及撤销。 4、熟悉Linux进程间通信。 第4周-第6周:了解Linux历史 第7周-第9周:学习Linux进程相关内核代码。 第10周-第13周:学习Linux多进程编程 第14周-第15周:系统性总结及论文撰写、修改论文阶段。 [1]Daniel P.Bovet & Marco Cesati 深入理解Linux内核(第三版):中国电力出版社,2007.9 [2]Michael Beck,Harald Bohme,Mirko Dziadzka,Ulrich Kunitz,Robert Magnus,Claus Schroter,Dirk Verworner linux内核编程指南(第三版):清华大学出版社,2004.10 [3]倪继利 Linux内核分析及编程:电子工业出版社,2005.9 指导教师签字: 年 月 日 教研室主任签字: 年 月 日
1
重庆邮电大学移通学院毕业设计(论文) 摘要
【摘要】自1991年Linus Torvalds将Linux带到这个世界上以来。经过20年的发展。Linux越来越受到众多计算机用户的青睐。Linux以其无与伦比的优越性,在现今这个众多操作系统共存的世界占有越来越重要的地位。
正因为Linux有极高的性能,所以现今高端计算机就成为了Linux的世界,据统计2010年全世界有80%的超级计算机上都是运行的Linux系统。在服务器领域,尤其是在WEB服务器方面,Linux成绩尤其突出。Linux平台下推出的LAMP(Linux+Apache+Mysql+PHP)架构体系所搭建的WEB服务占据了WEB流量的70%。
Linux是一个真正意义上的多用户多任务操作系统。Linux多进程技术继承了UNIX健壮而又成熟的技术,但Linux没照搬UNIX技术,而是天才版的革新了UNIX技术。这是其他操作系统无法比拟的。
Linux为用户提供了功能强大的API(Application Programming Interface,应用程序编程接口),这使得在Linux下进行程序的开发变得轻而易举。
本文所涉及到的内容有,Linux操作系统下进程的原理分析,多进程的创建,进程的调度,以及进程之间的相互通信。本文中的所有程序实例都采用C语言。 【关键词】 Linux,进程,内核分析,Linux编程
2
重庆邮电大学移通学院毕业设计(论文) Abstract
【Abstract】Linus Torvalds in 1991 to Linux come to this world。 After 20 years of growth。 Linux more and more get the favour of many computer users。 Linux unparalleled advantage, in this day and many operating systems coexist world plays more and more important position。
Because of Linux has extremely high performance, so now high-end computers became Linux world, according to statistics, the 2010 world has 80% of the super computer is running Linux system. In the server domain, especially in WEB server, Linux scores especially prominent. Linux launched the workbench technologies LAMP (Linux + Apache + Mysql + PHP) architecture system building WEB services accounted for 70% of WEB traffic.
Linux is a real sense of multi-user multitasking operating system. Linux multi-process technology inherited UNIX robust and mature technology, but Linux didn't copy UNIX technology, but genius version of the UNIX technology innovations. This is the other operating systems and incomparable.
Linux for users with a powerful API in the development of procedures under Linux becomes easy.
In this paper the content involved, Linux operating system, under the principle analysis process of multiple processes, process scheduling, create mutual communication between and processes。 In this paper are all the program examples using C language。
【Key Words】Linux;process; the kernel analysis; Linux programming
3
重庆邮电大学移通学院毕业设计(论文) 目录
前 言 ............................................................................................................................ 5 第1章 LINUX进程相关内核代码简要分析 .......................................................... 6
1.1 基本概念 ..................................................................................................................................... 6 1.1.1 进程 ...................................................................................................................................... 6 1.1.2 轻量级进程和线程 .............................................................................................................. 6 1.2进程的静态结构 ............................................................................................................................ 7 1.2.1进程描述符[1][3] ....................................................................................................................... 7 1.3进程的创建[1][8] .............................................................................................................................. 8 1.4 Linux进程调度[1][3][8][9][11] ............................................................................................................ 10 1.4.1 总述 ...................................................................................................................................... 10 1.4.2 runqueque结构[1][3] ............................................................................................................... 10 1.4.3 runqueque结构分析[3] .......................................................................................................... 11 1.5 进程的撤销[3] .............................................................................................................................. 13
第2章LINUX多进程编程 ....................................................................................... 14
2.1 进程的创建[1][2][3][7][15] ................................................................................................................. 14 2.1.1 fork()[1][3][15] ........................................................................................................................... 14 2.1.2 fork()与vfork()区别[3] ........................................................................................................... 16 2.2 exec函数族[1][2][3][15] ..................................................................................................................... 17 2.2.1简介 ....................................................................................................................................... 17 2.2.2 exec()函数族解析[3] .............................................................................................................. 18 2.3 进程间通信[1][2][3][4][7] .................................................................................................................. 21 2.3.1 总述 ...................................................................................................................................... 21 2.3.2 管道[10] ................................................................................................................................. 21 2.3.3 信号[4][6][16] ........................................................................................................................... 29 2.3.4消息队列[3][4] ......................................................................................................................... 39 2.3.5 共享内存[1][2][3][4] ................................................................................................................. 46 2.3.6 Socket[15] ................................................................................................................................ 49
第3章LINUX多进程编程应用 ............................................................................... 52
3.1 Linux网络服务器中的 ................................................................................................................ 52 3.1.1 传统的TCP进程并发服务器程序[15] ................................................................................. 52 3.1.2 TCP预先派生子进程并发服务器程序 ............................................................................. 52
结束语 .......................................................................................................................... 55 致 谢 .......................................................................................................................... 56 参考文献 ...................................................................................................................... 57 附件 .............................................................................................................................. 58
1. 英文原文 ....................................................................................................................................... 58 GNU/Linux profile .......................................................................................................................... 58
4
重庆邮电大学移通学院毕业设计(论文) 前言
前 言
Linux是类UNIX系统大家族中的一员。从20实际90年代末开始,Linux这位相对比较新的成员突然变得非常流行,并且跻身于那些知名的商用UNIX操作系统之列。
Linux以其无与伦比的优越性,已经在高档计算机占有了一席之地。而现今众多Linux桌面版的推出也使一般用户能够体验到Linux所到来的高性能,和高稳定性。
Linux能够吸引众多的用户不仅仅因为其性能和稳定性,另一个关键的因素是Linux内核的所有源代码对用户开放。这样,任何用户都可以从用户接口层到与硬件密切相关的核心层,对这个最成功的系统而又最现代的操作系统做深入的研究。
本人所介绍的Linux多进程编程所用编程语言为C语言,程序测试环为Ubuntu10.04,C语言编译器为GCC4.5。命令解释器为Bash。
本论文的体系主要分为以下几章。 第一章:Linux进程相关内核代码简要分析 第二章:Linux多进程编程 第三章:Linux多进程编程应用
5