贵 州 大 学
2002届研究生学位论文
基于Linux 操作系统的进程研究及其应用
学科专业 计算机软件与理论
研究方向 计算机软件
导 师 李 祥 教 授
研
究 生 王京辉
中国
· 贵州
· 贵阳
2001 年 12 月
致 谢:
衷心感谢导师李祥教授!从论文的选题、可行性研究、文献的收集、到研究工作的开展,特别是论文的撰写,老师给予了无微不至的关怀,提出了许多富有建设性的意见。导师认真、严谨、踏实的科研作风和渊博的学识,使我受益非浅。今后唯有加倍努力,以报答导师的培育之情。
最后,感谢所有关心和帮助过我的人们!
谢谢!
目
录
摘要
第一章Linux
和 Linux 的内核
1.1
Linux简介
1.2
Linux的内核:
1.2.1
Linux内核的特征
1.2.2 分析Linux内核的意义
第二章Linux
的内核结构
2.1 Linux内核在操作系统中的位置
2.2
Linux内核的抽象结构
2.3
各个子系统之间的依赖关系
第三章
Linux下的进程管理
3.1 进程和进程相关的简单描述:
3.1.1 进程简单说明
3.1.2 进程及作业
3.1.3 进程的切换
3.1.4 多进程系统具有以下一些突出的特点
3.2 Linux下的进程
3.2.1 Linux下的进程数据结构
3.2.2 Linux的多处理器系统中的调度
3.2.3 Linux下时钟和定时器
第四章
Linux的与进程有关的存储管理和进程创建
4.1 i386体系结构与kernel 2.2.x存储管理
4.2 Linux以Kernel 2.2.x为内核的进程管理
第五章
Linux进程之间的通信
5.1信号
5.2管道
5.3 SVR的进程间通信机制
5.4信号灯
5.5共享内存
第六章
Linux下线程
6.1线程的基本概念
6.2 线程的实行和创建
6.3 LinuxThreads线程库
6.4线程间通信
6.6守护线程分析
第七章
应用实例
7.1引起进程受限的起因
7.2对于这一问题的解决方案
7.3方案具体的实现
7.4方案总结
第八章
进行一步的工作
参考文献
摘 要
Linux最初是由芬兰赫尔辛基大学的Linus
Torvalds创建。
Linus把Linux建立在一个基于PC机上运行的,小的,名为minix的UNIX的基础之上。Linux允许免费地自由运用该系统源代码,并且鼓励其他人进一步对其进行开发。通过互连网和其它途径,任何人都有机会辅助开发和调试Linux的内核,链接新的软件,编写文档或者帮助新用户。实际上,并没有单独的组织负责开发此系统,Linux团体大部分通过邮递列表和USENET的消息组通信。许多协定已跳过开发过程,如果你想将自己的代码包括进"正式"内核,只需要给Linux Torvalds发一个E-mail,他就会进行测试并包括进内核。
Linux系统本身采用彻底开发,注重特性的方法进行设计。一般规律是大约隔几个月就发行一个Linux内核的新版本。Linux开发的动力不在于追求完美,无故障,而是要开发UNIX的免费实现。
Linux 具有以下特点:
1.
多任务
2.
虚拟存储
3.
TCP/IP驱动
4.共享库
5.多用户
6.保护模式.
进程管理是操作系统最为关键的部分,它的设计和实现直接影响到整个系统的性能。在一个多进程的操作系统中,一个时间段内可以有多个进程“并发”执行。这样就避免了较为快速的cpu等待较为低速的I/O设备的情况,提高了cpu利用率,从而提高系统的性能。另一个方面,同时运行多个进程,就可以同时提供多种服务或者同时为更多的客户服务,这也是现代操作系统的基本任务。
Linux中的线程是轻量级线程(lightweight
thread)。Linux的线程调度是由内核调度程序完成的,每个线程有自己的ID号。与进程相比,它们消耗的系统资源较少,创建较快,相互间的通信也较容易。存在于同一进程中的线程会共享一些信息,这些信息包括全局变量,进程指令,大部分数据,信号处理程序和信号设置,打开的文件,当前工作的目录以及用户ID和用户组ID.
在现代的操作系统中,一方面,要求越来越复杂,功能越来越多,另一方面,嵌入方式的开发又要求有越来越简单的管理机制,因此对于进程的管理也要求向两个方向发展,Linux 提供了开发的源代码,并且许多人已经进行了大量的工作,鉴于我国由于在操作系统研究的不足,造成安全问题的隐患,越来越多的公司和企业,开始重视
Linux,同时对于内核的研究也逐渐深入。1
对于Linux极其内核的分析,一方面,有利于开发适合我国自己的操作系统,操作系统是所有软件生存的基础,我们需要拥有自己的操作系统,而且对国家安全和国防事业都至关重要。如果搞和国际标准不兼容的操作系统,结果也会严重的阻碍软件业的发展,而Linux正符合我们的要求,因为代码公开,可以立即加入开发,又因为是国际化的,不必考虑兼容性的问题,而且不会同国际脱轨。另外一方面有利于开发高水平的软件。自由软件联盟涵盖了操作系统,开发语言,视窗系统,数据库,网络,文字处理等各个领域。目前Linux的源代码包含了世界各地无数计算机高手的作品,分析这些源代码对于我们掌握核心技术和各种驱动程序的编写会起到很好的作用。
本文首先简单介绍了Linux和Linux的内核,然后从Linux内核在操作系统中的位置,Linux内核的抽象结构和内核中各个子系统之间的依赖关系,详细分析了Linux的内核结构;本文的重点在于对于进程的管理分析,首先介绍了进程的相关概念,然后分析了在Linux下的进程具体实现结构,包括进程的数据结构,多处理器系统中的调度和时钟和定时器,并且在实现中涉及了和进程有关的存储管理部分和进程之间的通信部分;线程是小的进程,本文介绍了线程的概念,实行和创建,LinuxThreads线程库和线程通信等等。最后通过对Linux内核相关部分的修改,完成了在特殊用途下的进程实现实际应用。
本文的主要工作如下:
本文的创新在于经过详细的分析 Linux 的进程机制,并且从进程的高度讨论了多线程的应用之后,在现有的硬件和软件无法更改的情况下,但是要求有更多的任务同时执行的时候,也就是要求有更多的进程同时工作,通过修改内核关于进程的管理的部分来实现进程数量的增大,完成相应进程数量的需要。突破默认最大进程数的限制。在这一问题中必须解决没有足够的gdt表项的问题。Gdt的大小是硬件限制的,本文的通过动态地设置进程的描述符,取消为进程预先分配空间的做法,内核中可以动态地寻址到每个进程的tss 和ldt 段,因此在任务切换时不再由于 Linux 进程数的限制而拒绝服务,使用给该方法可以突破对于 512 个进程的限制。其应用已经在上海环境检测系统的局域网中应用,采用这样的做法可以节约开支,经济有效。
关键词:Linux 进程 内核 操作系统 内核结构 进程管理 存储管理 进程数据结构 调度通信机制 线程LinuxThreads线程库 线程间通信 守护线程 进程数 进程的描述符 环境检测
Abstract
Linux
has come from a
The Linux Kernel contains all of the features that we would expect in
any Operating System. Some of the features included are:
1.Multitasking (a technique for sharing a single processor
between several independent jobs)
2.Virtual Memory (allows repetitive, extended use of the
computer's RAM for performance
enhancement)
3.Fast TCP/IP Drivers (for speedy communication)
4.Shared Libraries (enable applications to share common
code)
5.Multi-user Capability (this means hundreds of people can
use the computer at the same time,either over a
network, the Internet, or on laptops/computers or terminals connected to the
serial ports of those computers).
6.Protected Mode (allows programs to access physical memory,
and protects stability of the
system)
Processes
manage is key to operating system, which designs and realize directly effect to
all systemic performance. In a multi-process operating system, many processes
run in the same time as to heighten the utilize rate of CPU and enhance the
capability of system. On the other hand, running many processes at the same
time, it could supply multi-serves and serve to more customers. This is the
basic task of modern operating system.
Threads are mini-processes. The Linux thread scheduler is scheduled by Linux
kernel. A thread has its ID. Compete to process, they are create quickly and
use little source. It’s easy to communion between them. Some of threads which
existed in a process could share some information, such as variables, process
instructs, data, signal manages and set signals.
In modern operating systems, one side, demand
more and more complexity for the increasing functions. On the other hand, the
mode of the simple manage systems is need .So manage process develop to two
orientation.
Learning from Linux kernel, we could develop our
operate systems. Operate systems are base of modest computer
. Without operate systems, we lost safe. In our country, due to the
deficiency of research operating systems, more firms and corporations worried
their safe and wake up to the security of computers , then
commence the Linux kernel researches. .Under this surroundings, the
researches of Linux kernels is important. One the other hand, Linux
offers original codes and many persons already carried a lot of work. Learning
those codes could develop our program level. The open sources include operate
system, language, windows system, database, net and word process.In
order to develop our program and learn the kernel of technology, we should work
for Liunx and other open sources.
This
article, firstly, simple introduces about Linux and its kernel, then talks
about the location of the Linux kernel in the operating systems, the abstract
structure of Linux kernels and the relation of each subsystems. We analyse Linux kernel structures. The emphases of article is
analyse of manage processes. At last, we touch about
threads. Threads are "light weight processes" (LWPs).
The main of work as follow,
Under
conditions of hardwares and softwares
cannot change, a firm requests more tasks to do at the
same time. It requests more processes run .Now we changed kernel which about
manage processes part, then break through the default
processes counts. This application has applied by ShangHui
environment inspect system. It works efficiency.
KeyWords: Linux Process Kernel Operating system Kernel structures Threads