Question: writing Linux kernel modules to create a new device file and an entry in the proc file system. The objectives of this project is to

writing Linux kernel modules to create a new device file and an entry in the proc file system.

The objectives of this project is to learn:

1. How to write a helloworld Linux kernel module.

 Create a Helloworld kernel module 

The following code is a complete helloworld module. #include

#include

#include

int init_new_module ( void)

{

p ri n t k (KERN_INFO " Hell o , world ! n" ) ;

return 0 ;

}

void exit_new_module ( void)

{

p ri n t k (KERN_INFO "Goodbye , world ! n" ) ;

}

module_init ( init_new_module ) ;

module_exit ( exit_new_module ) ;

***The module defines two functions. init_module is invoked when the module is loaded into the kernel and cleanup_module is called when the module is removed from the kernel. module_init and module_exit are special kernel macros to indicate the role of these two functions. Use the following makefile to compile the module.

ob j−m += new_module . o

a l l :

sudo make −C / l i b /modules /$ ( s h e l l uname −r ) / b uil d M=$ (PWD) modules

cl e a n :

sudo make −C / l i b /modules /$ ( s h e l l uname −r ) / b uil d M=$ (PWD) cl e a n

***To insert the module into the Linux kernel:

# insmod new_module.ko

Use the following command to verify the module has been loaded:

# lsmod

To remove the module from the kernel:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here is the reformatted and slightly updated code to solve this assignment newmodulec i... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Operating System Questions!