/proc的内核模块 [英] Kernel module for /proc

查看:148
本文介绍了/proc的内核模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写一个内核模块,该内核模块在/proc中创建名为mymod的目录,并且其中的文件名为mymodfile.写入该文件时,该文件应接受1到3之间的数字,并且在读取时根据已写入该文件的数字返回以下消息:

•1:当前系统时间(以微秒为单位)
•2:系统正常运行时间
•3:系统中当前的进程数

How to write a kernel module that creates a directory in /proc named mymod and a file in it name is mymodfile. This file should accept a number ranged from 1 to 3 when written into it and return the following messages when read based on the number already written into it:

• 1: Current system time (in microseconds precision)
• 2: System uptime
• 3: Number of processes currently in the system

输出"

root@Paradise# echo 1 > /proc/mymod/mymodfile
root@Paradise# cat /proc/mymod/mymodfile
08:30:24 342us
root@Paradise# echo 2 > /proc/mymod/mymodfile
root@Paradise# cat /proc/mymod/mymodfile
up 1 day, 8 min 
root@Paradise# echo 3 > /proc/mymod/mymodfile
root@Paradise# cat /proc/mymod/mymodfile
process count: 48 

请给我一些如何编写内核模块以及如何编译和安装内核模块的提示.

please give me some hint how to write a kernel modules and how to compile and install it .

推荐答案

您正在寻找的是 Linux内核模块编程指南,特别是部分/proc文件系统上,其中记录了很多有关如何添加新条目的示例.

What you're looking for is the Linux Kernel Module Programming Guide, specifically the section on the /proc filesystem, which has well documented examples of how to add new entries.

这篇关于/proc的内核模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆