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?...
- 11-02-2008 #1Just 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?
- 11-06-2008 #2
You can read /proc/modules file inside you kernel if your system support procfs.
- 11-20-2008 #3Just 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..
- 12-01-2008 #4Just Joined!
- Join Date
- Nov 2008
- Posts
- 9
Hi,
If possible can you share the code for doing so.
- 12-02-2008 #5Just 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("%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.


Reply With Quote
