linux 内核进程 kondemand,使用hello.ko驱动遍历内核中所有task进程和task中comm域打印分析...

#include#include#include#include#includeMODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)

{

struct task_struct *task,*p;

struct list_head *pos;

int count=0;

printk(KERN_ALERT"Hello World enter begin:\n");

task=&init_task;

list_for_each(pos,&task->tasks)

{

p=list_entry(pos, struct task_struct, tasks);

count++;

printk(KERN_ALERT"%d--->%s\n",p->pid,p->comm);

}

printk(KERN_ALERT"the number of process is:%d\n",count);

return 0;

}

static void hello_exit(void)

{

printk(KERN_ALERT"hello world exit\n");

}

module_init(hello_init);

module_exit(hello_exit);

/*Makefile文件:

obj-m :=process.o

CURRENT_PATH := $(shell pwd)

LINUX_KERNEL_PATH :=  /lib/modules/`uname -r`/build

all:

make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules

clean:

rm -rf .*.cmd *.o *.mod.c *.ko .tmp_versions Module.symvers .Makefile.swp

*/

luther@gliethttp:/vobs/tmp$ make

make -C /lib/modules/`uname -r`/build M=/vobs/tmp modules

make[1]: Entering directory `/usr/src/linux-headers-2.6.27-7-generic'

CC [M]  /vobs/tmp/process.o

Building modules, stage 2.

MODPOST 1 modules

LD [M]  /vobs/tmp/process.ko

make[1]: Leaving directory `/usr/src/linux-headers-2.6.27-7-generic'

luther@gliethttp:/vobs/tmp$ insmod ./process.ko |dmesg

[ 6326.126304] Hello World enter begin:

[ 6326.126328] 1--->init

[ 6326.126333] 2--->kthreadd

[ 6326.126338] 3--->migration/0

[ 6326.126342] 4--->ksoftirqd/0

[ 6326.126347] 5--->watchdog/0

[ 6326.126351] 6--->migration/1

[ 6326.126355] 7--->ksoftirqd/1

[ 6326.126359] 8--->watchdog/1

[ 6326.126364] 9--->events/0

[ 6326.126368] 10--->events/1

[ 6326.126372] 11--->khelper

[ 6326.126377] 51--->kintegrityd/0

[ 6326.126382] 52--->kintegrityd/1

[ 6326.126386] 54--->kblockd/0

[ 6326.126390] 55--->kblockd/1

[ 6326.126395] 57--->kacpid

[ 6326.126399] 58--->kacpi_notify

[ 6326.126403] 161--->cqueue

[ 6326.126408] 165--->kseriod

[ 6326.126412] 210--->pdflush

[ 6326.126416] 211--->pdflush

[ 6326.126420] 212--->kswapd0

[ 6326.126425] 254--->aio/0

[ 6326.126429] 255--->aio/1

[ 6326.126433] 1242--->ksuspend_usbd

[ 6326.126438] 1244--->khubd

[ 6326.126442] 1277--->ata/0

[ 6326.126446] 1283--->ata/1

[ 6326.126450] 1290--->ata_aux

[ 6326.126455] 1302--->khpsbpkt

[ 6326.126459] 2045--->scsi_eh_0

[ 6326.126463] 2046--->scsi_eh_1

[ 6326.126468] 2095--->knodemgrd_0

[ 6326.126472] 2107--->scsi_eh_2

[ 6326.126477] 2108--->scsi_eh_3

[ 6326.126481] 2247--->kjournald

[ 6326.126485] 2422--->udevd

[ 6326.126490] 2613--->kmmcd

[ 6326.126494] 2832--->kpsmoused

[ 6326.126498] 3670--->b43

[ 6326.126502] 4483--->portmap

[ 6326.126507] 4505--->rpc.statd

[ 6326.126511] 4513--->rpciod/0

[ 6326.126516] 4514--->rpciod/1

[ 6326.126520] 4524--->nfsiod

[ 6326.126525] 4532--->rpc.idmapd

[ 6326.126529] 4674--->getty

[ 6326.126534] 4675--->getty

[ 6326.126538] 4681--->getty

[ 6326.126542] 4683--->getty

[ 6326.126547] 4684--->getty

[ 6326.126551] 4859--->acpid

[ 6326.126555] 4893--->kondemand/0

[ 6326.126560] 4895--->kondemand/1

[ 6326.126565] 4976--->syslogd

[ 6326.126569] 5026--->dd

[ 6326.126573] 5028--->klogd

[ 6326.126577] 5051--->dbus-daemon

[ 6326.126582] 5073--->avahi-daemon

[ 6326.126586] 5074--->avahi-daemon

[ 6326.126591] 5104--->sshd

[ 6326.126595] 5151--->cupsd

[ 6326.126599] 5411--->exim4

[ 6326.126604] 5467--->hddtemp

[ 6326.126608] 5563--->lockd

[ 6326.126612] 5564--->nfsd4

[ 6326.126616] 5565--->nfsd

[ 6326.126620] 5566--->nfsd

[ 6326.126625] 5567--->nfsd

[ 6326.126629] 5568--->nfsd

[ 6326.126633] 5569--->nfsd

[ 6326.126637] 5570--->nfsd

[ 6326.126641] 5571--->nfsd

[ 6326.126645] 5572--->nfsd

[ 6326.126650] 5576--->rpc.mountd

[ 6326.126654] 5620--->nmbd

[ 6326.126658] 5622--->smbd

[ 6326.126663] 5634--->smbd

[ 6326.126667] 5648--->winbindd

[ 6326.126671] 5656--->winbindd

[ 6326.126676] 5680--->xinetd

[ 6326.126680] 5694--->hald

[ 6326.126684] 5697--->console-kit-dae

[ 6326.126689] 5698--->hald-runner

[ 6326.126694] 5780--->hald-addon-inpu

[ 6326.126698] 5790--->hald-addon-cpuf

[ 6326.126703] 5791--->hald-addon-acpi

[ 6326.126708] 5794--->hald-addon-stor

[ 6326.126712] 5844--->bluetoothd

[ 6326.126717] 5853--->btaddconn

[ 6326.126721] 5854--->btdelconn

[ 6326.126726] 5869--->krfcommd

[ 6326.126730] 5908--->NetworkManager

[ 6326.126735] 5919--->wpa_supplicant

[ 6326.126740] 5924--->nm-system-setti

[ 6326.126744] 5944--->gdm

[ 6326.126749] 5947--->gdm

[ 6326.126753] 5952--->Xorg

[ 6326.126758] 5968--->system-tools-ba

[ 6326.126763] 6004--->atd

[ 6326.126767] 6032--->cron

[ 6326.126771] 6106--->loop0

[ 6326.126775] 6122--->kjournald

[ 6326.126780] 6131--->getty

[ 6326.126784] 6182--->x-session-manag

[ 6326.126788] 6189--->dhclient

[ 6326.126793] 6283--->scim-launcher

[ 6326.126798] 6311--->scim-helper-man

[ 6326.126803] 6312--->scim-panel-gtk

[ 6326.126808] 6314--->scim-launcher

[ 6326.126812] 6330--->ssh-agent

[ 6326.126817] 6346--->dbus-launch

[ 6326.126822] 6349--->dbus-daemon

[ 6326.126826] 6353--->pulseaudio

[ 6326.126831] 6356--->gconf-helper

[ 6326.126835] 6358--->gconfd-2

[ 6326.126840] 6364--->seahorse-agent

[ 6326.126844] 6368--->gvfsd

[ 6326.126849] 6374--->gnome-keyring-d

[ 6326.126854] 6376--->gnome-settings-

[ 6326.126859] 6379--->gvfs-fuse-daemo

[ 6326.126864] 6384--->gnome-keyring-d

[ 6326.126868] 6386--->metacity

[ 6326.126873] 6409--->gnome-panel

[ 6326.126877] 6411--->nautilus

[ 6326.126882] 6415--->bonobo-activati

[ 6326.126886] 6428--->gnome-screensav

[ 6326.126891] 6432--->gvfs-hal-volume

[ 6326.126896] 6434--->gvfs-gphoto2-vo

[ 6326.126901] 6437--->gvfsd-burn

[ 6326.126905] 6442--->multiload-apple

[ 6326.126910] 6445--->trashapplet

[ 6326.126915] 6446--->sensors-applet

[ 6326.126919] 6449--->gvfsd-trash

[ 6326.126925] 6460--->fast-user-switc

[ 6326.126931] 6463--->mixer_applet2

[ 6326.126936] 6468--->bluetooth-apple

[ 6326.126940] 6469--->nm-applet

[ 6326.126945] 6471--->evolution-alarm

[ 6326.126950] 6472--->python

[ 6326.126954] 6473--->update-notifier

[ 6326.126959] 6482--->gnome-power-man

[ 6326.126964] 6581--->notification-da

[ 6326.126968] 6626--->sh

[ 6326.126973] 6627--->gnome-terminal.

[ 6326.126977] 6631--->firefox

[ 6326.126982] 6643--->run-mozilla.sh

[ 6326.126987] 6647--->firefox-bin

[ 6326.126992] 6648--->gnome-pty-helpe

[ 6326.126996] 7121--->bash

[ 6326.127000] 7150--->vim

[ 6326.127005] 7183--->loop1

[ 6326.127009] 7251--->smplayer

[ 6326.127013] 7282--->mplayer

[ 6326.127017] 7283--->mplayer

[ 6326.127022] 7343--->bash

[ 6326.127026] 7551--->bash

[ 6326.127030] 7567--->vim

[ 6326.127034] 7571--->bash

[ 6326.127039] 7753--->bash

[ 6326.127043] 7978--->insmod

[ 6326.127047] 7981--->udevd

[ 6326.127051] the number of process is:162

[ 6497.680803] hello world exit

[ 6500.975158] Hello World enter begin:

[ 6500.975183] 1--->init

[ 6500.975188] 2--->kthreadd

[ 6500.975193] 3--->migration/0

[ 6500.975197] 4--->ksoftirqd/0

[ 6500.975201] 5--->watchdog/0

[ 6500.975205] 6--->migration/1

[ 6500.975210] 7--->ksoftirqd/1

[ 6500.975214] 8--->watchdog/1

[ 6500.975218] 9--->events/0

[ 6500.975222] 10--->events/1

[ 6500.975226] 11--->khelper

[ 6500.975231] 51--->kintegrityd/0

[ 6500.975235] 52--->kintegrityd/1

[ 6500.975240] 54--->kblockd/0

[ 6500.975244] 55--->kblockd/1

[ 6500.975248] 57--->kacpid

[ 6500.975252] 58--->kacpi_notify

[ 6500.975256] 161--->cqueue

[ 6500.975261] 165--->kseriod

[ 6500.975265] 210--->pdflush

[ 6500.975269] 211--->pdflush

[ 6500.975273] 212--->kswapd0

[ 6500.975277] 254--->aio/0

[ 6500.975281] 255--->aio/1

[ 6500.975285] 1242--->ksuspend_usbd

[ 6500.975290] 1244--->khubd

[ 6500.975294] 1277--->ata/0

[ 6500.975298] 1283--->ata/1

[ 6500.975302] 1290--->ata_aux

[ 6500.975306] 1302--->khpsbpkt

[ 6500.975311] 2045--->scsi_eh_0

[ 6500.975315] 2046--->scsi_eh_1

[ 6500.975319] 2095--->knodemgrd_0

[ 6500.975323] 2107--->scsi_eh_2

[ 6500.975328] 2108--->scsi_eh_3

[ 6500.975332] 2247--->kjournald

[ 6500.975336] 2422--->udevd

[ 6500.975340] 2613--->kmmcd

[ 6500.975344] 2832--->kpsmoused

[ 6500.975349] 3670--->b43

[ 6500.975353] 4483--->portmap

[ 6500.975357] 4505--->rpc.statd

[ 6500.975361] 4513--->rpciod/0

[ 6500.975366] 4514--->rpciod/1

[ 6500.975370] 4524--->nfsiod

[ 6500.975374] 4532--->rpc.idmapd

[ 6500.975378] 4674--->getty

[ 6500.975382] 4675--->getty

[ 6500.975386] 4681--->getty

[ 6500.975390] 4683--->getty

[ 6500.975395] 4684--->getty

[ 6500.975399] 4859--->acpid

[ 6500.975403] 4893--->kondemand/0

[ 6500.975408] 4895--->kondemand/1

[ 6500.975412] 4976--->syslogd

[ 6500.975416] 5026--->dd

[ 6500.975420] 5028--->klogd

[ 6500.975424] 5051--->dbus-daemon

[ 6500.975429] 5073--->avahi-daemon

[ 6500.975433] 5074--->avahi-daemon

[ 6500.975437] 5104--->sshd

[ 6500.975441] 5151--->cupsd

[ 6500.975445] 5411--->exim4

[ 6500.975449] 5467--->hddtemp

[ 6500.975453] 5563--->lockd

[ 6500.975458] 5564--->nfsd4

[ 6500.975462] 5565--->nfsd

[ 6500.975466] 5566--->nfsd

[ 6500.975470] 5567--->nfsd

[ 6500.975474] 5568--->nfsd

[ 6500.975478] 5569--->nfsd

[ 6500.975482] 5570--->nfsd

[ 6500.975486] 5571--->nfsd

[ 6500.975490] 5572--->nfsd

[ 6500.975494] 5576--->rpc.mountd

[ 6500.975498] 5620--->nmbd

[ 6500.975502] 5622--->smbd

[ 6500.975506] 5634--->smbd

[ 6500.975510] 5648--->winbindd

[ 6500.975514] 5656--->winbindd

[ 6500.975519] 5680--->xinetd

[ 6500.975523] 5694--->hald

[ 6500.975527] 5697--->console-kit-dae

[ 6500.975531] 5698--->hald-runner

[ 6500.975535] 5780--->hald-addon-inpu

[ 6500.975540] 5790--->hald-addon-cpuf

[ 6500.975544] 5791--->hald-addon-acpi

[ 6500.975549] 5794--->hald-addon-stor

[ 6500.975554] 5844--->bluetoothd

[ 6500.975558] 5853--->btaddconn

[ 6500.975562] 5854--->btdelconn

[ 6500.975566] 5869--->krfcommd

[ 6500.975571] 5908--->NetworkManager

[ 6500.975575] 5919--->wpa_supplicant

[ 6500.975579] 5924--->nm-system-setti

[ 6500.975584] 5944--->gdm

[ 6500.975588] 5947--->gdm

[ 6500.975592] 5952--->Xorg

[ 6500.975596] 5968--->system-tools-ba

[ 6500.975600] 6004--->atd

[ 6500.975604] 6032--->cron

[ 6500.975608] 6106--->loop0

[ 6500.975612] 6122--->kjournald

[ 6500.975616] 6131--->getty

[ 6500.975620] 6182--->x-session-manag

[ 6500.975625] 6189--->dhclient

[ 6500.975629] 6283--->scim-launcher

[ 6500.975634] 6311--->scim-helper-man

[ 6500.975638] 6312--->scim-panel-gtk

[ 6500.975642] 6314--->scim-launcher

[ 6500.975647] 6330--->ssh-agent

[ 6500.975651] 6346--->dbus-launch

[ 6500.975655] 6349--->dbus-daemon

[ 6500.975660] 6353--->pulseaudio

[ 6500.975664] 6356--->gconf-helper

[ 6500.975668] 6358--->gconfd-2

[ 6500.975673] 6364--->seahorse-agent

[ 6500.975677] 6368--->gvfsd

[ 6500.975681] 6374--->gnome-keyring-d

[ 6500.975687] 6376--->gnome-settings-

[ 6500.975691] 6379--->gvfs-fuse-daemo

[ 6500.975695] 6384--->gnome-keyring-d

[ 6500.975700] 6386--->metacity

[ 6500.975704] 6409--->gnome-panel

[ 6500.975708] 6411--->nautilus

[ 6500.975713] 6415--->bonobo-activati

[ 6500.975717] 6428--->gnome-screensav

[ 6500.975722] 6432--->gvfs-hal-volume

[ 6500.975726] 6434--->gvfs-gphoto2-vo

[ 6500.975731] 6437--->gvfsd-burn

[ 6500.975735] 6442--->multiload-apple

[ 6500.975739] 6445--->trashapplet

[ 6500.975744] 6446--->sensors-applet

[ 6500.975748] 6449--->gvfsd-trash

[ 6500.975752] 6460--->fast-user-switc

[ 6500.975757] 6463--->mixer_applet2

[ 6500.975761] 6468--->bluetooth-apple

[ 6500.975766] 6469--->nm-applet

[ 6500.975770] 6471--->evolution-alarm

[ 6500.975774] 6472--->python

[ 6500.975778] 6473--->update-notifier

[ 6500.975783] 6482--->gnome-power-man

[ 6500.975787] 6581--->notification-da

[ 6500.975791] 6626--->sh

[ 6500.975796] 6627--->gnome-terminal.

[ 6500.975800] 6631--->firefox

[ 6500.975805] 6643--->run-mozilla.sh

[ 6500.975809] 6647--->firefox-bin

[ 6500.975813] 6648--->gnome-pty-helpe

[ 6500.975818] 7121--->bash

[ 6500.975822] 7150--->vim

[ 6500.975826] 7183--->loop1

[ 6500.975830] 7251--->smplayer

[ 6500.975834] 7282--->mplayer

[ 6500.975838] 7283--->mplayer

[ 6500.975842] 7343--->bash

[ 6500.975846] 7551--->bash

[ 6500.975850] 7567--->vim

[ 6500.975854] 7571--->bash

[ 6500.975858] 7753--->bash

[ 6500.975862] 8031--->a.out [ 6500.975866] 8032--->a.out // 这是打开的2个sleep测试程序,所以可见comm就是进程的名字

[ 6500.975870] 8048--->insmod

[ 6500.975874] 8051--->udevd

[ 6500.975878] the number of process is:164

luther@gliethttp:/vobs/tmp$

阅读(2246) | 评论(0) | 转发(0) |

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值