Hello Work Driver (step 2)

Source: Internet
Author: User

DriverProgramHello. 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
Default:
Make-C $ (kerneldir) M = $ (shell PWD) Modules
Clean:
Make-C $ (kerneldir) M = $ (shell PWD) clean
Install:
Insmod hello. Ko
Uninstall:
Rmmod hello. Ko
Clean:
Make-C $ (kerneldir) M = $ (shell PWD) clean
######################################## #######

After compilation, there is no error in insmod hello. Ko installation, but you cannot see "Hello, world". Run the dmesg command to check whether the installation is successful.

However, when rmmod hello is displayed, the error "error: removing 'hello': device or resource busy" occurs ".. Check whether the system does not compile the load control function ??? (Like impossible ). The answer is currently fruitless. Run the lsmod | grep Hello command to check if the hello driver does not exist. Dynamically load the driver so that it does not exist after the reset ....

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.