[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why hello kernel module didn't output anything?
On Thu, Oct 04, 2001 at 02:08:00PM -0400, Hong Hsu wrote:
> Here is my simple question:
> Compile following hello.c with gcc -c hello.c -Wall, then insmod hello.o
> -o mytest
Add -O2 or your module *will* fail. Also add -D__KERNEL__ -DMODULE.
> The /proc/modules shows "mytest 528 0 (unused)"
> But how the module will be called as it suppose to send "Hello, world "
> to either xterm or konsole?
Not if you don't tell the kernel what the module init and exit
functions are.
> Thanks,
> -Hong
>
>
> #define __KERNEL__ /* We're part of the kernel */
> #define MODULE /* Not a permanent part, though. */
>
> /* #include <linux/modversions.h> */
> #include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
>
> int init_module()
static int init_module()
> {
> printk("Hello, world - this is the kernel speaking\n");
>
> return 0;
> }
>
> void cleanup_module()
static void cleanup_module()
> {
> printk("Short is the life of an LKM\n");
> }
module_init(init_module);
module_exit(cleanup_module);
MODULE_AUTHOR("Hong Hsu");
MODULE_DESCRIPTION("Test module");
EXPORT_NO_SYMBOLS;
Erik
--
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands
Phone: +31-15-2783635 Fax: +31-15-2781843 Email: J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
IRC Channel: irc.openprojects.net / #kernelnewbies
Web Page: http://www.kernelnewbies.org/