1. 程式人生 > >linux驅動打印當前進程名命令與 pid

linux驅動打印當前進程名命令與 pid

TBase ren pro code cpi 2.4 sin function mac

hello.c

#include <linux/kernel.h> /*Needed by all modules*/
#include <linux/module.h> /*Needed for KERN_* */
#include <linux/init.h> /* Needed for the macros */
#include <asm/current.h>
#include <linux/sched.h>
MODULE_LICENSE("GPL");
static int hello_init(void)
{
printk(KERN_WARNING "the process is\"%d\"(pid %i)\n",current->comm, current->pid);
  return 0;
}

static void hello_exit(void)
{
  printk("Bye, kernel!\n");
}

/* main module function*/
module_init(hello_init);
module_exit(hello_exit);
root@ubuntu:~/Desktop# insmod ./hello.ko
root@ubuntu:~/Desktop# tail /var/log/kern.log
Aug 26 07:05:06 ubuntu kernel: [   38.280651] audit: type=1400 audit(1535292306.730:64): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="/usr/sbin/cupsd" pid=2130 comm="apparmor_parser"
Aug 26 07:19:41 ubuntu kernel: [  913.186836] e1000: eth0 NIC Link is Down
Aug 26 07:19:45 ubuntu kernel: [  917.188835] e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
Aug 26 07:22:25 ubuntu kernel: [ 1076.499433] e1000: eth0 NIC Link is Down
Aug 26 07:22:29 ubuntu kernel: [ 1080.499470] e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
Aug 26 07:31:10 ubuntu kernel: [ 1602.402400] hello: module verification failed: signature and/or required key missing - tainting kernel
Aug 26 07:31:10 ubuntu kernel: [ 1602.408784] Hello kernel, it‘s 2018!
Aug 26 07:31:10 ubuntu kernel: [ 1602.408792] the process is"1383225440"(pid 3571)
Aug 26 07:32:39 ubuntu kernel: [ 1691.260987] Bye, kernel!
Aug 26 07:33:50 ubuntu kernel: [ 1762.382921] the process is"1656784352"(pid 3890)
root@ubuntu:~/Desktop# 

lsmod

root@ubuntu:~/Desktop# lsmod
Module                  Size  Used by
hello                  16384  0 
coretemp               16384  0 
crct10dif_pclmul       16384  0 
crc32_pclmul           16384  0 
aesni_intel           167936  0 
snd_ens1371            28672  0 
snd_ac97_codec        131072  1 snd_ens1371
aes_x86_64             20480  1 aesni_intel
gameport               16384  1 snd_ens1371
ac97_bus               16384  1 snd_ac97_codec
vmw_balloon            16384  0 
lrw                    16384  1 aesni_intel
gf128mul               16384  1 lrw
glue_helper            16384  1 aesni_intel
ablk_helper            16384  1 aesni_intel
snd_pcm               102400  2 snd_ac97_codec,snd_ens1371
cryptd                 20480  2 aesni_intel,ablk_helper
snd_seq_midi           16384  0 
snd_seq_midi_event     16384  1 snd_seq_midi
input_leds             16384  0 
joydev                 20480  0 
serio_raw              16384  0 
snd_rawmidi            32768  2 snd_ens1371,snd_seq_midi
snd_seq                69632  2 snd_seq_midi_event,snd_seq_midi
vmwgfx                172032  3 
snd_seq_device         16384  3 snd_seq,snd_rawmidi,snd_seq_midi
ttm                    94208  1 vmwgfx
snd_timer              32768  2 snd_pcm,snd_seq
btusb                  45056  0 
drm_kms_helper        126976  1 vmwgfx
snd                    81920  7 snd_ac97_codec,snd_timer,snd_pcm,snd_seq,snd_rawmidi,snd_ens1371,snd_seq_device
btrtl                  16384  1 btusb
btbcm                  16384  1 btusb
btintel                16384  1 btusb
drm                   360448  6 ttm,drm_kms_helper,vmwgfx
soundcore              16384  1 snd
vmw_vmci               65536  0 
i2c_piix4              24576  0 
shpchp                 36864  0 
nfit                   32768  0 
rfcomm                 69632  8 
bnep                   20480  2 
8250_fintek            16384  0 
bluetooth             512000  25 bnep,btbcm,btrtl,btusb,rfcomm,btintel
binfmt_misc            20480  1 
mac_hid                16384  0 
parport_pc             32768  0 
ppdev                  20480  0 
lp                     20480  0 
parport                49152  3 lp,ppdev,parport_pc
hid_generic            16384  0 
usbhid                 49152  0 
hid                   118784  2 hid_generic,usbhid
psmouse               126976  0 
mptspi                 24576  2 
mptscsih               40960  1 mptspi
mptbase                98304  2 mptspi,mptscsih
ahci                   36864  0 
libahci                32768  1 ahci
e1000                 131072  0 
scsi_transport_spi     32768  1 mptspi
pata_acpi              16384  0 
root@ubuntu:~/Desktop# 

linux驅動打印當前進程名命令與 pid