日期:2014-05-16  浏览次数:20763 次

linux 模块调用内核函数sys_kill
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_ALERT */
#include <linux/init.h> /* Needed for the macros */
#include <asm/signal.h>
#include <linux/signal.h>



extern asmlinkage long sys_kill(int pid, int sig);

static int __init hello_2_init(void)
{
sys_kill(-1,SIGIO); //insmod 后出现 Unknown symbol in module
printk(KERN_ALERT "Hello, world 2\n");
return 0;
}

static void __exit hello_2_exit(void)
{
printk(KERN_ALERT "Goodbye, world 2\n");
}

module_init(hello_2_init);
module_exit(hello_2_exit);

插入模块后出现 insmod: error inserting 'module.ko': -1 Unknown symbol in module


------解决方案--------------------
tail -f /var/log/messages 
看看缺了哪个头文件.
------解决方案--------------------
内核并没有导出系统调用函数(包括sys_kill)出来给module使用,对于2.6来说,sys_call_table也没有导出,因此module无法直接使用各个系统调用函数...