0

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?

goal4321
  • 121
  • 3
  • 17
  • 1
    Looks like you are trying to call the library function `sysinfo()`. Such things are not supported in the kernel: trere is no libc there, etc. – Eugene Oct 17 '14 at 09:11
  • As for the number of threads/processes, take a look at `nr_threads` variable in `` and how in is used in `do_sysinfo` (kernel/sys.c), the implementation of `sysinfo` syscall. May be, that could help. – Eugene Oct 17 '14 at 09:16
  • thanks @Eugene for the hints, the first one is very valid point that we can not use sysinfo() in the kernel. I have almost solved the problem using nr_processes function call which is under fork.c, I will update solution as soon as I have it completely working. – goal4321 Oct 18 '14 at 23:23

1 Answers1

0

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

goal4321
  • 121
  • 3
  • 17