我正在尝试实现一个内核模块,该模块可以访问用户进程的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)
我不知道如何进行,如果有人可以帮助我,将不胜感激。
frob_task_by_pid_hard
及其类似物)中的大部分都是纯GPL的,因此,除非您将模块的许可证声明为GPL,否则您将无处可寻。也要这样填写模块上的其他样板数据:MODULE_AUTHOR,MODULE_DESCRIPTION,MODULE_LICENSE至少。