2016-03-04 81 views
1

我已经添加了一个hello world系统调用到Linux内核3.16,然后我编译并运行它。我通过syscall函数调用了我的系统调用,但它没有打印任何东西,并且syscall函数的输出不是-1。我怎样才能找到我的系统调用被添加到内核?

这是我的系统调用代码:

#include <linux/kernel.h> 

asmlinkage long sys_hello(void){ 
    printk("hello world\n"); 
    return 0; 
} 

,这我的C程序代码来调用我的系统调用:

#include <stdio.h> 
#include <unistd.h> 
#include <sys/types.h> 
#include <pwd.h> 
#include <string.h> 
#include <errno.h> 

int main(void){ 
    printf("function\n"); 
    if(syscall(317)==-1){ 
     printf("no\n"); 
    } 
    else{ 
     printf("yes\n"); 
    } 
    return 0; 
} 

C程序的输出是:

function 
yes 

我怎样才能找到我的系统调用正确添加到内核?

+0

您是否尝试过使用strace等工具调试执行? –

+0

我不知道dmesg。它试图dmesg和它的工作 – hamid

回答

1

printk不一定会打印到您当前的tty;看到你的消息在shell中使用dmesg命令。另请参见this one如果它不显示在dmesg

+0

非常感谢你,它的工作。如果我想知道我的系统调用添加到内核而不运行它的功能,我该怎么办? – hamid