I want to develop a SYSCALL in Linux that read the output of /proc/loadavg and prints the first column.
The idea is to print the first value of CPU load from cat /proc/loadavg i.e. 0.01 0.50 0.10 1/25 1800
using a syscall.
For example:
#include <unistd.h>
#include <sys/syscall.h>
#include <stdio.h>
int main() {
printf("SYSCALL OUTPUT: %s\t", syscall(223, 1)); //(223) - syscall number (1) - for first cpu load
return 0;
}
OUTPUT - SYSCALL OUTPUT: 0.01
Until now, using information on internet, I have made a simple Hello World kind of SYSCALL:
#include <linux/kernel.h>
#include <linux/syscalls.h>
SYSCALL_DEFINE0(newprint)
{
printk("SYSCALL: Hello World!\n");
return 0;
}
But, I have no idea how to build a complex Syscall that does the things I want to. Therefore, I am looking for some help that includes things like –
- How to create complex syscalls in linux?
- How to import functions from
~/kernel/sched/loadavg.c
to use in my SYSCALL program? - After able to perform the above steps, How to compile the syscall program to get the output like a normal c program.