http://blog.ednchina.com/fafen/267973/message.aspxIf you want to compile the sum-module (source mirrored below), follow these steps:
Create the Makefile in your directory with the sum-module.cobj-m := sum-module.o
KDIR := /lib/modules/$(shell uname -r)/buildPWD := $(shell pwd)
default:$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
Now do amake
... and the sum-module.ko is built.If you get something like this
# makemake: Nothing to be done for `default'.
you need to install the kernel source and compile the kernel first (run "make" at least to the point until
all "HOSTCC scripts/" stuff is done - this will configure your kernel and allows external module compilation).
Make sure /lib/modules/$(shell uname -r)/build points to your build directory (most likely /usr/src/linux...).Another reason for the above error can be, that your browser converted the TAB before $(MAKE) to spaces.
Make sure there is a TAB before $(MAKE).
Install it with install.sh:
#!/bin/shinstall -m 644 sum-module.ko /lib/modules/`uname -r`/kernel/drivers/sum-module.ko
/sbin/depmod -a (adjust the /lib/modules path according to your needs)Now make a
# modprobe sum-module
Or if you don't want to install the module, do this:
# insmod ./sum-module.ko
..and if your system doesn't freeze you've done it right ;-)
For kernel 2.4, the Makefile would look like this:
TARGET := modulename
INCLUDE := -I/lib/modules/`uname -r`/build/includeCFLAGS := -O2 -Wall -DMODULE -D__KERNEL__ -DLINUX
CC := gcc ${TARGET}.o: ${TARGET}.c
$(CC) $(CFLAGS) ${INCLUDE} -c ${TARGET}.c(not yet tested)
sum-module source from: http://www.win.tue.nl/~aeb/linux/lk/lk-9.html/*
* sum-module.c
# modprobe sum-module.o
# ls -l /proc/arith
total 0
dr-xr-xr-x 2 root root 0 Sep 30 12:40 .
dr-xr-xr-x 89 root root 0 Sep 30 12:39 ..
-r--r--r-- 1 root root 0 Sep 30 12:40 sum
# cat /proc/arith/sum
0
# echo 7 > /proc/arith/sum
# echo 5 > /proc/arith/sum
# echo 13 > /proc/arith/sum
# cat /proc/arith/sum
25
# rmmod sum-module
# ls -l /proc/arith
ls: /proc/arith: No such file or directory
#
*/
#include <linux/module.h>
#include <linux/init.h>#include <linux/proc_fs.h>
#include <asm/uaccess.h>
static unsigned long long sum;
static int show_sum(char *buffer, char **start, off_t offset, int length) {
int size;
size = sprintf(buffer, "%lld\n", sum);*start = buffer + offset;
size -= offset;return (size > length) ? length : (size > 0) ? size : 0;
}
/* Expect decimal number of at most 9 digits followed by '\n' */static int add_to_sum(struct file *file, const char *buffer,
unsigned long count, void *data)
{
unsigned long val = 0;char buf[10];
char *endp;
if (count > sizeof(buf))
return -EINVAL;if (copy_from_user(buf, buffer, count))
return -EFAULT;
val = simple_strtoul(buf, &endp, 10);
if (*endp != '\n')
return -EINVAL;
sum += val; /* mod 2^64 */
return count;
}
static int __init sum_init(void) {
struct proc_dir_entry *proc_arith;
struct proc_dir_entry *proc_arith_sum;
proc_arith = proc_mkdir("arith", 0);if (!proc_arith) {
printk (KERN_ERR "cannot create /proc/arith\n");
return -ENOMEM;
}
proc_arith_sum = create_proc_info_entry("arith/sum", 0, 0, show_sum);
if (!proc_arith_sum) {
printk (KERN_ERR "cannot create /proc/arith/sum\n");
remove_proc_entry("arith", 0);
return -ENOMEM;
}
proc_arith_sum->write_proc = add_to_sum;
return 0;
}
static void __exit sum_exit(void) {
remove_proc_entry("arith/sum", 0);
remove_proc_entry("arith", 0);
}
module_init(sum_init);
module_exit(sum_exit);
MODULE_LICENSE("GPL");
from:
| 只有注冊用戶登錄后才能發(fā)表評論。 | ||
|
||
|
相關(guān)文章:
|
||
網(wǎng)站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
|
||
|
|
| |||||||||
| 日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
|---|---|---|---|---|---|---|---|---|---|
| 30 | 1 | 2 | 3 | 4 | 5 | 6 | |||
| 7 | 8 | 9 | 10 | 11 | 12 | 13 | |||
| 14 | 15 | 16 | 17 | 18 | 19 | 20 | |||
| 21 | 22 | 23 | 24 | 25 | 26 | 27 | |||
| 28 | 29 | 30 | 31 | 1 | 2 | 3 | |||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 | |||
常用鏈接
留言簿(10)
隨筆分類(307)
- Algorithm(22)

- apache(1)

- Assembly(1)

- browser(2)

- C++_BASIS(39)

- Compiling Theorem(1)

- CPU(1)

- cvs(3)

- Database(8)

- Designed Patterns(3)

- FileFormat(4)

- FileSystem(1)

- freebsd(1)

- Game(2)

- gdb(1)

- Gossips(12)

- GP_STL(3)

- interview(8)

- java

- life and living(1)

- linux kernel(12)

- Linux_Coding(43)

- Linux_Driver

- Linux_SysAdmin(26)

- makefile(3)

- misce(5)

- MultiCore(1)

- Network(14)

- OS(18)

- RegularExpression(1)

- schedule(1)

- SearchEngine(1)

- security(2)

- Shell(25)

- Socket(18)

- storage(2)

- Template(4)

- VC_MFC(4)

- vi(5)

- website(1)

- windows(7)

隨筆檔案(297)
- 2012年10月 (1)
- 2012年9月 (1)
- 2012年7月 (1)
- 2012年6月 (7)
- 2012年5月 (3)
- 2012年4月 (2)
- 2011年9月 (3)
- 2011年8月 (3)
- 2011年6月 (3)
- 2011年5月 (2)
- 2011年3月 (2)
- 2011年1月 (1)
- 2010年12月 (2)
- 2010年11月 (6)
- 2010年10月 (4)
- 2010年9月 (7)
- 2010年8月 (12)
- 2010年7月 (6)
- 2010年6月 (5)
- 2010年5月 (11)
- 2010年4月 (16)
- 2010年3月 (20)
- 2010年2月 (18)
- 2010年1月 (26)
- 2009年12月 (34)
- 2009年11月 (36)
- 2009年10月 (5)
- 2009年9月 (1)
- 2009年7月 (2)
- 2009年6月 (3)
- 2009年5月 (6)
- 2009年4月 (6)
- 2009年3月 (11)
- 2009年2月 (6)
- 2008年11月 (1)
- 2008年10月 (1)
- 2008年9月 (3)
- 2008年8月 (4)
- 2008年7月 (16)
algorithm
- andytan
- algorithm, linux, os, network,etc
- EXACT STRING MATCHING ALGORITHMS
- httperf -- a web perf test tool
- Java多線程
- 編程夜未眠
- 布薩空間
- 結(jié)構(gòu)之法
- 沈一峰 google技術(shù)博客
- 小兵的窩
Books_Free_Online
C++
- Bjarne Stroustrup's C++ Style and Technique FAQ
- boyplayee column
- C Plus Plus
- CPP Reference
- LearnC++Website
- Welcome to Bjarne Stroustrup's homepage!
database
Linux
Linux shell
linux socket
misce
- cloudward
- 感覺這個博客還是不錯,雖然做的東西和我不大相關(guān),覺得看看還是有好處的
network
OSS
- Google Android
- Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This early look at the Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
- os161 file list
overall
搜索
最新評論

- 1.?re: memcached完全剖析系列教程《轉(zhuǎn)》
- mark
- --zgpxgame
- 2.?re: 用prctl給線程命名
- 評論內(nèi)容較長,點擊標題查看
- --none
- 3.?re: 用prctl給線程命名
- 請問大俠: 用top命令的時候可以顯示修改后的線程名么?如何做呢?
- --dhao123@sina.com
- 4.?re: 解決Linux pthread_create內(nèi)存泄漏問題
-
我試過,每一種方法有的時候不行。
第二種是可以的。
- --朱先生
- 5.?re: 著名程序庫的比較和學習經(jīng)驗
- 評論內(nèi)容較長,點擊標題查看
- --buy dissertation
- 6.?re: linux的消息隊列與共享內(nèi)存編程
- 內(nèi)容選擇得很好,謝謝
- --朱志超
- 7.?re: 著名程序庫的比較和學習經(jīng)驗
- 評論內(nèi)容較長,點擊標題查看
- --LillianHancock
- 8.?re: 解決Linux pthread_create內(nèi)存泄漏問題[未登錄]
- 不錯,支持一個。
- --jack
- 9.?re: 淺談游戲服務(wù)器---功能模塊上來看[未登錄]
- 不錯 好文!! 期待博主繼續(xù)
- --cppexplore
- 10.?re: 全面整理的C++面試題
- 評論內(nèi)容較長,點擊標題查看
- --chatler
- 11.?re: 微軟面試中簡單的算法題目(轉(zhuǎn))
- 評論內(nèi)容較長,點擊標題查看
- --chatler
- 12.?re: Browsers, processes, cookies and session state
- 每個IE Instance該是不同的進程吧,可以獲取進程ID,在每個instance里建一個名稱包含進程id的目錄名,就可以分目錄存儲了吧。
- --chatler
- 13.?re: Browsers, processes, cookies and session state
-
文章說的很清楚,多謝
我有一個問題:
如何為每個ie instance ie實例的 Persistent cookies cookie 指定不同的存儲目錄? - --domolo
- 14.?re: 從一道面試題看指針與數(shù)組的區(qū)別
- 一個字,強!
- --路過
- 15.?re: 一個關(guān)于單向鏈表的面試題
- 評論內(nèi)容較長,點擊標題查看
- --chatler
閱讀排行榜
- 1.?Windows Socket五種I/O模型(8351)
- 2.?最大公約數(shù)(Gcd)兩種算法(Euclid && Stein)<轉(zhuǎn)>(5506)
- 3.?用prctl給線程命名(5074)
- 4.?Linux core dump file詳解 <轉(zhuǎn)>(4501)
- 5.?算法面試題(3410)
- 6.?64位與32位編程的數(shù)據(jù)類型區(qū)別(3247)
- 7.?解決Linux pthread_create內(nèi)存泄漏問題(3158)
- 8.?NUMA與英特爾下一代Xeon處理器學習心得<轉(zhuǎn)>(3006)
- 9.?c語言抓取網(wǎng)頁數(shù)據(jù)(2842)
- 10.?CVSNT服務(wù)器配置——添加用戶、解決無法登陸(2749)
- 11.? pthread_join函數(shù)及l(fā)inux線程(2653)
- 12.?一個基于Event Poll(epoll)的TCP Server Framework,淺析epoll(2597)
-
13.?為 C/C++ 項目構(gòu)建您自己的內(nèi)存管理器
(2577) - 14.?memcached完全剖析系列教程《轉(zhuǎn)》(2521)
- 15.?G++編譯選項(2412)
- 16.?STL容器 erase的使用陷井<轉(zhuǎn)載>(2206)
- 17.?epoll使用例子(2131)
- 18.?linux的消息隊列與共享內(nèi)存編程(2078)
- 19.?gdb帶參數(shù)調(diào)試(2068)
- 20.?The Linux Kernel Module Programming Guide(2024)
- 21.?一個關(guān)于單向鏈表的面試題(1919)
- 22.?c中strncmp與memcmp的區(qū)別(1891)
- 23.?優(yōu)化Derby數(shù)據(jù)庫技巧(1842)
- 24.?一個基于完成端口的TCP Server Framework,淺析IOCP(1768)
- 25.?自己整理的指令(1758)
- 26.?Google C++ Style Guide(1651)
- 27.?autotools制作Makefile 和configure文件(1648)
- 28.?An In-Depth Look into the Win32 Portable Executable File Format(1636)
- 29.?linux系統(tǒng)調(diào)用函數(shù)(1635)
- 30.? vim大小寫轉(zhuǎn)換(1591)
- 31.?淺談游戲服務(wù)器---功能模塊上來看(1563)
-
32.?MIPS architecture
(1526) - 33.?教你用c實現(xiàn)http協(xié)議(1513)
- 34.?Aix下查看占用端口的進程(1487)
- 35.?史上最強bash函數(shù)庫(1415)
- 36.?linux trap詳解(1348)
- 37.?ms,google,vmware,nvidia美國總部面試題(1333)
- 38.?多CPU上的原子操作(1327)
- 39.?power函數(shù)寫法《轉(zhuǎn)》(1291)
-
40.?Critical Section
(1261)
評論排行榜
- 1.?著名程序庫的比較和學習經(jīng)驗(3)
- 2.?用prctl給線程命名(2)
-
3.?Browsers, processes, cookies and session state
(2) - 4.?解決Linux pthread_create內(nèi)存泄漏問題(2)
- 5.?一個關(guān)于單向鏈表的面試題(1)
- 6.?從一道面試題看指針與數(shù)組的區(qū)別 <轉(zhuǎn)>(1)
- 7.?淺談游戲服務(wù)器---功能模塊上來看(1)
- 8.?微軟面試中簡單的算法題目(轉(zhuǎn))(1)
- 9.?全面整理的C++面試題(1)
- 10.?memcached完全剖析系列教程《轉(zhuǎn)》(1)
- 11.?linux的消息隊列與共享內(nèi)存編程(1)
- 12.?NAT的缺陷(0)
- 13.?Linux下面socket編程的非阻塞TCP 研究(0)
- 14.?教你用c實現(xiàn)http協(xié)議(0)
- 15.?c語言抓取網(wǎng)頁數(shù)據(jù)(0)
- 16.?CVSNT服務(wù)器配置——添加用戶、解決無法登陸(0)
- 17.?CVS的常用命令速查手冊(0)
- 18.?文本過濾工具GREP(0)
- 19.?A Beast of a Different Nature(0)
- 20.?跟我一起寫 Makefile(0)
- 21.?ar和nm命令的使用(0)
- 22.?epoll 精髓(0)
- 23.?epoll用法說明(0)
- 24.?IOCP(0)
- 25.?Linux系統(tǒng)共享內(nèi)存設(shè)置(0)
- 26.?proc文件系統(tǒng)(0)
- 27.?史上最強bash函數(shù)庫(0)
- 28.?Template specialization(0)
- 29.?type casting(0)
- 30.?CALLBACK, WINAPI, AFXAPI和函數(shù)調(diào)用方式(0)
- 31.?linux下靜/動態(tài)鏈接庫編程實例(0)
- 32.?A Description of the C++ typename keyword(0)
- 33.?How to Generate C++ Class Template Definitions(0)
- 34.?template friends(0)
- 35.? Linux下C語言歷遍目錄(0)
- 36.?HOWTO compile kernel modules for the kernel 2.6(0)
- 37.?Optimization of Computer Programs in C(0)
- 38.?自己整理的指令(0)
- 39.?Google之Page Rank分析(0)
- 40.?多CPU上的原子操作(0)
