Find the answer to your Linux question:
Results 1 to 4 of 4
I am just learning kernel modules for the first time So created this simple file Code: #include <linux/module.h> #include <linux/kernel.h> int init_module(void) { printk(KERN_INFO "init_module() called\n"); return 0; } void ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2011
    Posts
    96

    kernel module ?


    I am just learning kernel modules for the first time

    So created this simple file

    Code:
    #include <linux/module.h>
    #include <linux/kernel.h>
     
    int init_module(void)
    {
    	printk(KERN_INFO "init_module() called\n");
    	return 0;
    }
     
    void cleanup_module(void)
    {
    	printk(KERN_INFO "cleanup_module() called\n");
    }
    compiled it
    and loaded the module
    using sudo insmod hello.ko

    lsmod | grep hello shows

    hello 12394 0

    But I don't see my messages being printed to the screen even when I unload with rmmod ????

    What is going wrong with printk ?

  2. #2
    Just Joined!
    Join Date
    Apr 2011
    Posts
    96
    My mistake it is printing to dmesg | tail

    But how can I get it to print to the console.
    I have read this
    If the priority is less than int console_loglevel, the message is printed on your current terminal. If both syslogd and klogd are running, then the message will also get appended to /var/log/messages, whether it got printed to the console or not. We use a high priority, like KERN_ALERT, to make sure the printk() messages get printed to your console rather than just logged to your logfile. When you write real modules, you'll want to use priorities that are meaningful for the situation at hand.
    And I have tried using all the different KERN_... but it still doesn't show up?
    tried echo 8 > /proc/sys/kernel/print

    and cat /proc/sys/kernel/print shows

    8 4 1 7

    WTF
    Last edited by sam111; 11-15-2011 at 02:02 AM.

  3. #3
    Just Joined!
    Join Date
    Jul 2011
    Posts
    16
    Are you in GUI mode?. printk messages are sent to the console not to the pseudo terminals(pts). When you are in graphical mode and using any terminal like gnome-terminal, konsole, they use pseudo terminals not the console. Press Ctl + ALT + F1 and login and try.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Apr 2011
    Posts
    96
    Thanks I was doing it from using dmesg | tail all the time but that got to be a pain.
    Also you can do it in the GUI pts terminals by opening a second terminal tab and cat the kmsg file.
    This would show up in real time just like the ctl+alt+f1 did for me when loading and unloading my module.

    Thanks didn't know their was a differents between the c1+alt+f1 console and the kconsole ones.
    Looking into the device files I see their is a pts is this the kconsoles device file?
    I know the /dev/tty1 is ctl+alt+f1
    and /dev/ttyX is the ctrl + alt + f(2,3,..x)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •