I'm very new to kernel programming and I have written a small kernel module which is like this,
mod.c
#include<linux/kernel.h>
#include<linux/module.h>
#include<sys/sysinfo.h>
int init_module(void)
{
int k;
struct sysinfo info;
printk(KERN_INFO "hello\n");
k = sysinfo(&info);
printk(KERN_EMERG "procs = %d\n", info.procs)
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye\n");
}
and Makefile looks like this,
obj-m +=mod.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
if i issue make from terminal, it gives error
fatal error: sys/sysinfo.h: No such file or directory
could you tell me what's the problem here?
If anyone is still looking how to do this, I solved this sometime ago, Here is the solution. This works for debian Linux 3.16 version. If you want to take look at the code which is here.
https://github.com/st0rmi/rootkit_programming/blob/master/assignment01/assignment01_mod.c