目录
第一章 引言
1.1 Linux内核通信简介
1.2 本文的主要工作
第二章 Linux内核概述
2.1 内核空间和用户空间
2.2 内核态与用户态
2.3 Linux 内核模块的运行环境与传统进程间通信
第三章 八种通信方式
3.1 内核启动参数
3.2 模块参数和sysfs
3.3 Sysctl
3.4 系统调用
3.5 Netlink
3.6 Procfs
3.7 seq_file
3.8 debugfs
第四章 八种通信方式的优劣对比
第五章 总结
参考文献
附录
附录一、内核启动参数源代码
附录二、NetLink 源代码
附录三、Seq_file 源代码
摘要:Linux是一个自由、开放源代码的类UNIX操作系统,目前为止Linux已经被移植到各种硬件平台,其支持的种类远远超出其他操作系统。Linux内核是以C语言写成,并符合POSIX标准的操作系统,其将内存分为“内核空间”和“用户空间”两部分,驱动程序和操作系统在内核空间运行,应用程序在用户空间运行,linux内核空间程序需要与用户空间程序进行数据交换。本文首先调查linux内核空间的分布情况,并将内核间与传统进程间的通信方式做一个对比,找到传统进程间的通信方式不能用于内核与用户空间通信的原因,接着分别介绍Linux内核空间与用户空间通信的八种通信方式:内核启动参数、模块参数、Sysctl、系统调用、Netlink、Procfs、Seq_file、Debugfs;然后,本文还将研究Linux内核的编译方法和内核程序的编写,以及Linux内核模块的运行环境,并将这八种通信方式的实现在Linux3.2.1内核版本中测试成功;最后,本文对比了这8种通信方式的优劣,并给出了相应的应用场景。
关键词: Linux;内核空间;用户空间;数据通信
Linux kernel: Research and Implementation
of the communication between user space
and kernel space
Abstract: Linux is a free UNIX-like operating systems and open source, and the current Linux has been ported to a variety of computer hardware platform that supports the kind of far beyond any other operating system. Linux kernel is written in C and POSIX-compliant operating system, and its memory is divided into "kernel space" and "user space" , operating systems and drivers run in kernel space, the application runs in user space, linux kernel module and user module application program needs to exchange data. First, this paper will investigate the distribution of linux kernel space, and compare the communication between the kernel and the traditional way, find the reason of that traditional inter-process communication can not be used to communicate with the kernel space and the user, then we will introduce eight ways to communicate between Linux kernel space and user space: kernel boot parameter module parameters, Sysctl, system calls, Netlink, Procfs, Seq_file, Debugfs; next, this paper will also study the methods of build the Linux kernel, as well as Linux operating environment kernel modules, and communication methods to achieve the eight tested successfully in Linux3.2.1 kernel version; finally, we compare the advantages and disadvantages for the eight communication ways between linux kernel space and user space, also this paper presents the application scences for the eight ways.
Keywords: Linux; kernel space; user space; data communication