我有以下模块,我试图打印 PCB 信息。但是我无法弄清楚输出。它应该打印过程相关的数据。我很感激任何帮助。
修改pcb.c
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/fs_struct.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
void retrieve(struct task_struct *task) {
struct task_struct *ts = current;
struct list_head *list;
if(task->state == 1)
printk(KERN_INFO "Process Name%s", ts->comm);
printk(KERN_INFO "Process Name%lu", ts->min_flt);
printk(KERN_INFO "Process Name%lu", ts->maj_flt);
printk(KERN_INFO "Process Name%li", ts->utime);
printk(KERN_INFO "Process Name%li", ts->stime);
printk(KERN_INFO "Process Name%d", ts->pid);
printk(KERN_INFO "Process Name%u", ts->flags);
printk(KERN_INFO "Process Name%u", ts->start_time);
printk(KERN_INFO "Process Name%ld", ts->state);
list_for_each(list, ¤t->children) {
ts = list_entry(list, struct task_struct, sibling);
retrieve(ts);
}
}
static int __init pcbinfo_init(void)
{
struct task_struct *node = current;
printk(KERN_INFO "Starting module...\n");
for(;node->pid != 1; node = node->parent)
retrieve(node);
return 0;
}
static void __exit pcbinfo_cleanup(void)
{
printk(KERN_INFO "Cleaning module...\n");
}
module_init(pcbinfo_init);
module_exit(pcbinfo_cleanup);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("arioglu");
MODULE_DESCRIPTION("Prints PCB info");
生成文件
obj-m += modpcb.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
dmesg | tail
sudo insmod modpcb.ko
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
编辑:输出。通过使用 insmod 更新 Makefile,错误消失了。
make -C /lib/modules/4.4.0-45-generic/build M=/home/emre-ubuntu/Desktop/21202135/finalB modules
make[1]: Entering directory '/usr/src/linux-headers-4.4.0-45-generic'
Building modules, stage 2.
MODPOST 1 modules
make[1]: Leaving directory '/usr/src/linux-headers-4.4.0-45-generic'
dmesg | tail
[ 926.839624] cfg80211: (2457000 KHz - 2482000 KHz @ 40000 KHz), (N/A, 2000 mBm), (N/A)
[ 926.839626] cfg80211: (2474000 KHz - 2494000 KHz @ 20000 KHz), (N/A, 2000 mBm), (N/A)
[ 926.839628] cfg80211: (5170000 KHz - 5250000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2000 mBm), (N/A)
[ 926.839631] cfg80211: (5250000 KHz - 5330000 KHz @ 80000 KHz, 160000 KHz AUTO), (N/A, 2000 mBm), (0 s)
[ 926.839633] cfg80211: (5490000 KHz - 5730000 KHz @ 160000 KHz), (N/A, 2000 mBm), (0 s)
[ 926.839635] cfg80211: (5735000 KHz - 5835000 KHz @ 80000 KHz), (N/A, 2000 mBm), (N/A)
[ 926.839637] cfg80211: (57240000 KHz - 63720000 KHz @ 2160000 KHz), (N/A, 0 mBm), (N/A)
[ 926.840351] wlo1: associate with 04:18:d6:19:b7:61 (try 1/3)
[ 926.843708] wlo1: RX AssocResp from 04:18:d6:19:b7:61 (capab=0x421 status=0 aid=21)
[ 926.863483] wlo1: associated
sudo insmod modpcb.ko