19 June 2011

linux 2.6 simple module

Download simple-proc.c
Download Makefile.sim
# mv Makefile.sim Makefile
# make
# insmod ./simple-proc.ko

# echo "1" > /proc/arith/sum
# echo "11" > /proc/arith/sum
# echo "111" > /proc/arith/sum

# cat /proc/arith/sum
123

Download simple-module.c
Download Makefile.mod
# mv Makefile.mod Makefile
# make
# insmod ./simple-module.ko

# cat /proc/getprio
==> [120:120:120:0] [1000] [0x00402100] systemd [1][0]
==> [120:120:120:0] [1000] [0x8020A040] kthreadd [2][0]
==> [120:120:120:0] [1000] [0x8420A040] ksoftirqd/0 [3][2]
==> [120:120:120:0] [1000] [0x8420A060] kworker/u:0 [5][2]
==> [100:100:100:0] [1000] [0x8420A040] khelper [6][2]
==> [120:120:120:0] [1000] [0x8020A040] sync_supers [95][2]
==> [120:120:120:0] [1000] [0x80A0A040] bdi-default [97][2]
==> [100:100:100:0] [1000] [0x8420A040] kblockd [99][2]
==> [100:100:100:0] [1000] [0x8420A040] ata_sff [255][2]
==> [100:100:100:0] [1000] [0x8420A040] md [261][2]
==> [120:120:120:0] [1000] [0x8420A060] kworker/0:1 [359][2]
==> [120:120:120:0] [1000] [0x80A4A840] kswapd0 [370][2]
...
==> [79:120:79:20] [1000] [0x00400100] testrt [3264][2463]
...


Reference:
http://www.captain.at/programming/kernel-2.6
http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html

No comments:

Post a Comment