(1)Linux层次结构:
(2)Linux内核组成:
主要由进程调度(SCHED)、内存管理(MM)、虚拟文件系统(VFS)、网络接口(NET)和进程间通信(IPC)等5个子系统组成。
(3)与Unix的差异:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
/*
* hello_init 初始化函数,当模块装载时被调用,如果装载成功返回0,
* 否则返回非零值
*/
static int hello_init(void)
{
printk(KERN_ALERT "I bear a charmed life.\n");
return 0;
}
/*
* hello_exit 退出函数,当模块卸载时被调用
*/
static void hello_exit(void)
{
printk(KERN_ALERT "Out, out, brief candle!\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Qiushan");
MODULE_DESCRIPTION("A Hello, World Module");int my_init(void);
obj-m := hello.o make -C /kernel/source/location SUBDIRS=$PWD modules
sudo make modules_install sudo insmod hello.ko //装载 sudo rmmod hello //卸载
struct animal_struct {
char dog; /* 1 byte */
unsigned long cat; /* 4 bytes */
unsigned short pig; /* 2 bytes */
char fox; /* 1 byte */
};struct animal_struct {
char dog; /* 1 byte */
u8 __pad0[3]; /* 3 bytes */
unsigned long cat; /* 4 bytes */
unsigned short pig; /* 2 bytes */
char fox; /* 1 byte */
u8 __pad1; /* 1 byte */
};struct animal_struct {
unsigned long cat; /* 4 bytes */
unsigned short pig; /* 2 bytes */
char dog; /* 1 byte */
char fox; /* 1 byte */
};Linux内核设计基础(十)之内核开发与总结,布布扣,bubuko.com
原文地址:http://blog.csdn.net/bluecloudmatrix/article/details/30970725