Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
problem is that
printk is not giving message on the terminal
You are not in userspace.
printf() — print formatted strings to stdout (i.e., “the terminal”).
printk() — print formatted strings of a specific priority on the (circular) kernel log buffer.
It is up to you how to access the kernel log buffer. Some examples include using the dmesg utility, opening a userspace connection to /proc/kmsg, and using the userspace functions klogctl()/syslog().
but when i did cp makefile Makefile
it compiled succesfully.
When dealing with external module building, a makefile is usually the best way to go. If for some reason all built-ins in the kernel tree are not built, it may not assume KBUILD_EXTMOD and will instead try to build the module by descending into your directory and using your makefile (this method is used on page 24 of this book). Whenever this is done by the kernel build system, all makefiles should be named “Makefile” (other names include “Kbuild”).
If, for some reason, you want to continue using the one-liner, try appending the target “modules” to the command.
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>
static int hello3_data __initdata = 3;
static int __init hello_3_init(void)
{
printk(KERN_INFO "Hello, world %d\n", hello3_data);
return 0;
}
static void __exit hello_3_exit(void)
{
printk(KERN_INFO "Goodbye, world 3\n");
}
module_init(hello_3_init);
module_exit(hello_3_exit);
sir i have successfully compiled the above code but problem is that
printk is not giving message on the terminal ......
y is it so sir explain ...........
thank you..........
After you do insmod check out the dmesg
Code:
insmod MODULE-NAME
dmesg
it should be appear on last line the (module_init function)
and if you do
Code:
rmmod MODULE-NAME
dmesg
you'll receive on the last line the other message which is the module_exit function.
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>
static int hello3_data __initdata = 3;
static int __init hello_3_init(void)
{
printk(KERN_INFO "Hello, world %d\n", hello3_data);
return 0;
}
static void __exit hello_3_exit(void)
{
printk(KERN_INFO "Goodbye, world 3\n");
}
module_init(hello_3_init);
module_exit(hello_3_exit);
sir i have successfully compiled the above code but problem is that
printk is not giving message on the terminal ......
y is it so sir explain ...........
thank you..........
You can this in /var/tmp/message.for print message on terminal include linux/tty.h and then instead of printk write console_print(....).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.