Add a LINUX module

Source: Internet
Author: User

With experience in system calling, it is still very smooth to add modules.

 

[Lab environment]
Fedora, kernel 2.6.21.6

Lab procedure]
1. CD/root/homework/Module
2. VI process. c
3. Add the following code:
# Include <Linux/kernel. h> <br/> # include <Linux/init. h> <br/> # include <Linux/module. h> <br/> static int process_init (void) <br/> {<br/> int num = 0; <br/> struct task_struct * P; <br/> for_each_process (p) <br/>{< br/> struct task_struct * q = p-> parent; <br/> printk ("pid = %-5d, name = %-20 s, ", p-> tgid, p-> comm); <br/> printk (" PRIO = %-5d ,", p-> PRIO); <br/> printk ("my_parent is: % s [% d]/n", Q-> comm, Q-> tgid ); <br/> nu M ++; <br/>}< br/> printk ("/ntotal number is: % d/N", num); <br/> return num; <br/>}</P> <p> static void process_exit (void) <br/> {<br/> printk ("=======================/N "); <br/> printk ("process_exit, goodbye! /N "); <br/>}</P> <p> module_init (process_init); <br/> module_exit (process_exit ); <br/> module_license ("GPL"); <br/>

4. VI makefile

5. Add the following code:
OBJ-M: = process. o
ALL:
Make-C/lib/modules/$ (shell uname-R)/build M = $ (shell PWD) Modules
Clean:
Make-C/lib/modules/$ (shell uname-R)/build M = $ (shell PWD) clean

6. Make
7./sbin/init 3 enter the character Interface
8. insmod process. Ko Display Results
9. rmmod process. Ko is removed from the kernel and the result is displayed.

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.