I'm wondering if I can use the directory listing of
/sys/module instead of lsmod to get a list of currently loaded modules.
Is that the list of loaded modules only? Or maybe that combined with
Each loaded module has an entry in
/sys/module. But there are also kernel components with an entry in
/sys/module that are not loaded as modules. Each kernel component¹ that can be built as a module has an entry in
/sys/module, whether it is compiled and loaded as a module or compiled as part of the main kernel image.
lsmod gets the list of loaded modules from
I think that only loaded modules have an
initstate file in their
/sys/module directory, so you can use that too.
¹ That's each component of the loaded kernel. The kernel doesn't know or care what modules you may have in files on your hard disk. The kernel doesn't care what modules were built at the same time of the kernel image, either; it may show that via
/proc/config but it doesn't use that information for anything.