Programmatically check whether a linux kernel module exists or not at runtime

∥☆過路亽.° 提交于 2019-12-05 02:48:09

You can use popen and lsmod | grep trick:

  FILE *fd = popen("lsmod | grep module_name", "r");

  char buf[16];
  if (fread (buf, 1, sizeof (buf), fd) > 0) // if there is some result the module must be loaded
    printf ("module is loaded\n");
  else
    printf ("module is not loaded\n");

There is no such function. In fact, the source code of lsmod (lsmod.c) has the following line in it which should lead you to your solution:

file = fopen("/proc/modules", "r");

There is also a deprecated query_module but it appears to only exist in kernel headers these days.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!