I'm new on modules programming and I need to make a system call to retrieve the system processes and show how much CPU they are consuming.
How can I make this call?
I'm new on modules programming and I need to make a system call to retrieve the system processes and show how much CPU they are consuming.
How can I make this call?
Why would you implement a system call for this? You don't want to add a syscall to the existing Linux API. This is the primary Linux interface to userspace and nobody touches syscalls except top kernel developers who know what they do.
If you want to get a list of processes and their parameters and real-time statuses, use
/proc
. Every directory that's an integer in there is an existing process ID and contains a bunch of useful dynamic files whichps
,top
and others use to print their output.If you want to get a list of processes within the kernel (e.g. within a module), you should know that the processes are kept internally as a doubly linked list that starts with the
init
process (symbolinit_task
in the kernel). You should use macros defined ininclude/linux/sched.h
to get processes. Here's an example:This should be okay to gather information. However, don't change anything in there unless you really know what you're doing (which will require a bit more reading).
There are syscalls for that, called open, and read. The information of all processes are all kept in
/proc/{pid}
directories. You can gather process information by reading corresponding files.More explained here: http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html