When browsing through my filesystem, I saw a kernel module which I wrote a way back to print information about the current process and its stack, pid..etc.. Also, this module prints all the processes running in the system. So I loaded that into my running system and it was obedient 🙂
I had called him ‘process_informer.ko’..
[root@humbles-lap hello]# make
make -C /lib/modules/2.6.30.10-105.2.23.fc11.x86_64/build M=/misc/my_kernel_modules/hello modules
make[1]: Entering directory `/usr/src/kernels/2.6.30.10-105.2.23.fc11.x86_64′
CC [M] /misc/my_kernel_modules/hello/process_informer.o
Building modules, stage 2.
MODPOST 1 modules
CC /misc/my_kernel_modules/hello/process_informer.mod.o
LD [M] /misc/my_kernel_modules/hello/process_informer.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.30.10-105.2.23.fc11.x86_64′
[root@humbles-lap hello]#
[root@humbles-lap hello]# lsmod |grep process
[root@humbles-lap hello]# insmod process_informer.ko
[root@humbles-lap hello]# lsmod |grep process
process_informer 12427 0
[root@humbles-lap hello]#
[root@humbles-lap hello]# modinfo process_informer.ko
filename: process_informer.ko
license: GPL
description: Module, for fun
version: 1.0.0
author: Humble Chirammal
srcversion: C62BE5C41BEC6E733271884
depends:
vermagic: 2.6.30.10-105.2.23.fc11.x86_64 SMP mod_unload
[root@humbles-lap hello]#
[root@humbles-lap hello]# rmmod process_informer.ko
[root@humbles-lap hello]# lsmod |grep process
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683529] Hi World, somebody loaded me ==> __init()
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683533]
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683534] I am informed to track current process
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683538]
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683539] Current process is : ‘insmod’
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683540] pid : ‘8875’
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683541] Kernel release : ‘2.6.30.10-105.2.23.fc11.x86_64’
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683544] ‘RUNNABLE’ OR ‘UNRUNNABLE’
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683547] PRIO : 120 STATE: 0
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683550]
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683551] My thread_info located at : ffff88009d0dc000
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683552]
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683555] Process 0 is : swapper/0 pid :: 0
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683558] Process 1 is : systemd pid :: 1
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683561] Process 2 is : kthreadd pid :: 2
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683565] Process 3 is : ksoftirqd/0 pid :: 3
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683568] Process 4 is : migration/0 pid :: 6
Jun 1 00:01:17 humbles-lap kernel: [ 6225.683571] Process 5 is : watchdog/0 pid :: 7
************Truncated..
Jun 1 00:01:17 humbles-lap kernel: [ 6225.684065] Process 157 is : su pid :: 7296
Jun 1 00:01:17 humbles-lap kernel: [ 6225.684068] Process 158 is : bash pid :: 7306
Jun 1 00:01:17 humbles-lap kernel: [ 6225.684071] Process 159 is : bash pid :: 7398
Jun 1 00:01:17 humbles-lap kernel: [ 6225.684074] Process 160 is : su pid :: 7419
Jun 1 00:02:08 humbles-lap kernel: [ 6225.684117] Process 174 is : sleep pid :: 8856
Jun 1 00:02:08 humbles-lap kernel: [ 6276.449168] Bye Guys, he is kind enough to unload me ==> __exit()
Hmmmm.. there are ‘174’ processes in my system …
hello,
I am new to kernel programming world.
Can you please share the surge code of above mentioned kernel module?
Thanks in advance.