2

I have added a hello world system call to Linux kernel 3.16, then I compile and ran it. I called my system call by syscall function but it did not print any thing and output of syscall function was not -1.

This is my system call code:

#include <linux/kernel.h>

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

and this my c program code to call my system call:

#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;
}

The output of c program is:

function
yes

How can I find my system call is added to kernel correctly?

Elydasian
  • 2,016
  • 5
  • 23
  • 41
hamid
  • 694
  • 1
  • 8
  • 20

1 Answers1

2

printk wouldn't necessarily print to your current tty; to see your message use the dmesg command in your shell. See also this one if it does not show up on dmesg

Community
  • 1
  • 1
  • thank you so much, it worked. if i want to know my system call is added to kernel without running its function, what can i do? – hamid Mar 04 '16 at 18:21