Create UNIX "special character" file
Suppo开发者_运维百科se I want to create, in the spirit of /dev/zero, a file /dev/seven that produces the character '7' whenever it is read from. How should I go about doing something like this? Would I need to modify the kernel?
Yes, you'd need to create a driver for that special character device.
For linux, I'd suggest you read Linux Device Drivers by Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman. (Chapter 3 talks about char drivers, but do read at least the first two chapters also.)
A device driver is not necessary, a fifo special file plus a user program generating the stream of 7
is perfectly able to provide this behavior.
You'll need about a five line shell script, all told.
There's a short example of creating a device driver for Linux here, which might help to get you started:
- http://www.freesoftwaremagazine.com/articles/drivers_linux
精彩评论