How to determine if a specific module is loaded in linux kernel

前端 未结 9 1590
谎友^
谎友^ 2021-02-01 14:28

I am just curious is there any way to determine if a particular module is loaded/installed.

$lsmod lists all modules (device driver loaded).

Is there any way to

9条回答
  •  孤独总比滥情好
    2021-02-01 14:56

    I wrote this:

    MODULE=snd_aloop # for example
    test -n "$(grep -e "^$MODULE " /proc/modules)" && echo "Loaded" || echo "Not loaded"
    

    It checks in /proc/modules. If the module is mentioned there, it's assumed to be loaded, otherwise not.

    The others seemed too long to me (the other short one requires root, this does not). Of course it's just written out what was already mentioned as "alternatives".

    Caution: modprobe accepts some variants of module names other than the primary listed in /proc/modules. For example loading snd-aloop works, but the module is named snd_aloop and is listed as such in /proc/modules and when using rmmod that's also the only name that will work.

提交回复
热议问题