Linux's simplest Driver Model: helloworld! -- Linux general technology-Linux programming and kernel information. The following is a detailed description. 1. The file hello. c contains the following content:
# Ifndef _ KERNEL __
# Define _ KERNEL __
# Endif
# Ifndef MODULE
# Define MODULE
# Endif
# Include /* Printk */
# Include
# Include /* Module_init module_exit */
Static int _ init hello_init (void)
{
Printk ("hello world, my god! \ N ");
Return 0;
}
Static void _ exit hello_exit (void)
{
Printk ("bye, my god! \ N ");
}
2. Compile the driver
2.1 hardware environment Introduction:
2.1.1> redhat9 [linux-2.4.20-8] In vmwarevm
2.1.2> putty.exe remote ssh login to linux on vmware
2.1.3> Use winscp.exe in windows XP and copy remote small files from linux in vmware
2.1.4> vmware-> files-> Settings-> options-> sharing large files [/mnt/hgfs/] [gliethttp]
2.2 Preparation:
Since I'm using a linux testing system as a linux-2.4.20-8, first make sure that/usr/src/linux-2.4.20-8 exists
If it does not exist, download the linux-2.4.20-8 kernel source code, put it in any directory, just put the downloaded linux-2.4.20-8 kernel source code, put in
In the/usr/src directory, the preparation is complete.
2.3 compile
[Root @ gliethttp] # gcc-c hello. c-I/usr/src/linux-2.4.20-8/include
After success, the system generates hello. o in the same directory as hello. c.
2.4 execution
[Root @ gliethttp] # insmod hello. o
Hello world, my // display
[Root @ gliethttp] # lsmod // view the hello driver Unit
[Root @ gliethttp] # rmmod hello // remove from the system
Bye, my // display
NOTE: If it is executed in putty, the putty will not show the results, but the [gliethttp] will be displayed in vmware's tty.
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