2016-03-04 36 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