我正在尝试实现一个内核模块,它可以访问用户进程的 task_struct,其进程 ID 对我来说是已知的。我正在使用find_get_pid
并pid_task
获取流程的task_struct:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/pid.h>
#include <linux/pid_namespace.h>
int init_module( void )
{
//Declaring the variables
int p_id = 6980; //6980 is the process ID of my user process
struct pid *pid_struct;
struct task_struct *task;
// Trying to access the variables of the p_id
pid_struct = find_get_pid(p_id);
task = pid_task(pid_struct, PIDTYPE_PID);
//Printing the info from the task_struct
printk( KERN_INFO "*** [%d]\n",task->pid);
return 0;
}
void cleanup_module( void )
{
return;
}
它正在成功编译,我得到 *.ko 文件,但是当我试图将它插入内核时,它给了我一个错误:
insmod: error inserting 'main.ko': -1 Unknown symbol in module
Dmesg 给我以下输出:
main: Unknown symbol find_get_pid (err 0)
我不知道如何继续,它会如果有人可以帮助我,将不胜感激。