Find the answer to your Linux question:
Results 1 to 5 of 5
inside my LKM I would like to count the number of loaded modules inside the kernel, however the modules list isn't exported. How can I count this?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    1

    Counting number of modules in a LKM


    inside my LKM I would like to count the number of loaded modules inside the kernel, however the modules list isn't exported. How can I count this?

  2. #2
    Just Joined! alex1983-0112's Avatar
    Join Date
    Apr 2008
    Location
    Russia
    Posts
    16
    You can read /proc/modules file inside you kernel if your system support procfs.

  3. #3
    Just Joined!
    Join Date
    Nov 2008
    Location
    Bangalore
    Posts
    4
    I think procfs isn't used a lot nowadays...if procfs isn't supported try cd /sys/module...You will find all modules listed there..

  4. #4
    Just Joined!
    Join Date
    Nov 2008
    Posts
    9
    Hi,

    If possible can you share the code for doing so.

  5. #5
    Just Joined!
    Join Date
    Nov 2008
    Location
    Bangalore
    Posts
    4
    #include <stdio.h>
    #include <sys/types.h>
    #include <dirent.h>

    int main()
    {
    int count=0;
    DIR *stream;
    struct dirent *mod;
    stream=opendir("/sys/module");
    while(1)
    {
    mod=readdir(stream);
    if(mod==NULL)
    break;
    count++;
    }
    printf("&#37;d\n",count-2);
    }

    Use the above code to count number of modules in /sys/module.

    P.S. - I have printed count-2 because readdir also reads the "." and ".." that you see when you do ls -a.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •