views:

54

answers:

2

Hello guys,

i am new to linux, i am 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 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 that 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 futher information on printk)

also if guys could provide a simple but usefull system call that i could implement myself that would be great

A: 

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.

Jonathan
in the folders now, they arnt telling me much
molleman
They tell you everything, if you look in the right places.
Ignacio Vazquez-Abrams
but this is a homework assignment, and i need to be able to be able to give not normally avialable kernel information to the user(demonstrate capability for new system call not normally available to a non-root user)
molleman
Ohhhh... Perhaps you'd have better luck looking at the scheduler, then. Generally there isn't much output from that, since it needs to be so efficient, but you could add some instrumentation to count, say, context switches, processor affinity, ...
Jonathan
now, how would i go about looking at code(documentation) that would give me access to the scheduler
molleman
I'm not particularly familiar with it myself, as the system calls I added for a research project were like five years ago, but take a look at Con Kolivas's BFS patch. That should tell you where to look for scheduler stuff. http://ck.kolivas.org/patches/bfs/
Jonathan
A: 

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)

zengr
i need to be able get information within a systemcall of my own in the kernel, and then call that new system call. it should allow a non root user to call systemcalls
molleman