Review Linux driver basics Hello World

Source: Internet
Author: User

Linux driver manual loading insmod manual uninstall rmmod

Test Environment fedora10

 

Linux Device Driver Version 3:

 

/*************************************** ******/

Hello. c

 

# Include <Linux/init. h>
# Include <Linux/module. h>

Module_license ("dual BSD/GPL ");
Static int hello_init (void)
{
Printk (kern_alert "Hello, world/N ");
Return 0;
}
Static void hello_exit (void)
{
Printk (kern_alert "Goodbye, cruel world/N ");
}
Module_init (hello_init );
Module_exit (hello_exit );

 

 

#/************************************** *******/

Makefile:

 

OBJ-M: = Hello. o

Kerneldir? =/Lib/modules/$ (shell uname-R)/build
PWD: = $ (shell PWD)

ALL:
$ (Make)-C $ (kerneldir) M = $ (PWD)

 

Save the file and compile it using the make command.

# Make

# Insmod hello. Ko

# Rmmod hello. Ko

 

In my test environment, the following information is not displayed in/var/log/messages. So far, the compilation is successful.

 

Mar 27 17:01:30 localhost kernel: Hello, world
Mar 27 17:01:36 localhost kernel: Goodbye, cruel world

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.