开发者

When to use /proc and when /dev

I need to write a kernel module that is not a device driver. Th开发者_如何学编程at module will be communicating with some user space processes. As I dont want to use ioctl(), I am left with either creating a file in /proc directory or creating a device file in /dev directory.

Question: How do i decide between /proc and /dev. Is this just a judgement call or are there any unwritten agreements on using these two.


You will have a great deal of difficulty getting a new interface added into /proc/. The kernel developers are unhappy that it has become a dumping ground for miscellaneous interfaces, and unless you are actually modifying something about processes via /proc/pid/, I think you'll have trouble convincing the kernel community to accept it.

A device file in /dev/ may be acceptable, even for modules that aren't really device drivers. (e.g., /dev/kvm, /dev/pts, /dev/ecryptfs, /dev/fuse, /dev/kmsg, /dev/ptmx, etc.) However, device files are too-often easier to manipulate with ioctl(), and I think you're right to avoid it if you can.

The current trend in kernel circles is sysfs or custom filesystems. The sysfs approach is based upon single-value-per-file semantics, intended to be manipulated with echo and cat. It's wonderful for users if it works for you. Custom filesystems lets you write very specific binary-capable interfaces, and fs/libfs.c should help you write your own filesystem to your own needs. (I don't know anyone who has used configfs, but I've always thought it looked neat. Maybe it would suit your module?)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜