I am new to Linux, After implementing a simple system call on the Linux kernel that prints to the syslog via printk,
I would like to be able to extend this application , so I can get details on the battery percentage of my laptop or check the speed of the hard drive in the computer, could any of you give me a hand on where i would get the code t开发者_JAVA百科hat would help me access this type of information within my kernel,
(I have no idea how I found printk, and I have no idea where i could get further information on printk)
also if guys could provide a simple but useful system call that I could implement myself that would be great.
This should be a good starting point for you to learn about making system calls to the kernel. This cheatsheet also has a sample C code.
Download it here (pdf)
Check out /proc and /sys on your filesystem; between the two, you should be able to find everything you need without system calls.
For example:
- What is my CPU speed? Check
/proc/cpuinfo
- How much RAM do I have? Check
/proc/meminfo
- What size is
/dev/sda
? Check/sys/block/sda/size
Some things I'm not sure how to test (for example, the two things you asked about), but you may be able to find them with a little digging.
If you're really curious how stuff works, check out the source for the drivers for the devices you are interested in; they provide those filesystem entries, so they should (hopefully) document what is in each.
精彩评论