current position:Home>How to use lsmod in Linux (take a practical example)
How to use lsmod in Linux (take a practical example)
2022-01-27 01:21:29 【mikes zhang】
Linux The kernel is a mystery to most people , But it doesn't have to ! Welcome to the exciting lsmod The world , This tool allows you to view the modules being used by the kernel, etc !
What is? lsmod?
To explain lsmod This is allowed in Linux Tools for listing modules in the kernel , First, you must understand what the module is .Linux A module is a piece of modular code ( Run in compiled format ), You can choose from Linux Kernel load or unload . The main advantage of using these modules is their modularity and granularity .
You can think of kernel modules as plug-ins in other software . Whenever you need a specific —— Less common or common —— When the function , It can be used as a plug-in , Or in Linux In the case of kernel, it is used as a module . Plug ins in other software and Linux There is little difference between kernel modules . however , They work The level is closer to the hardware and core running software , Not at the end of the stack at the user level .
for example , Your graphics card driver —— Especially when you use NVidia Driver —— Load as a kernel module . Error installing driver , The kernel module will be configured and loaded ( Maybe the next time the system restarts ).
go back to lsmod, It should be included in your Linux The default installation of the operating system , The tool will list an overview of the currently available kernel modules .
lsmod: At first sight
Interestingly , it lsmod Is a kind of will ( fictitious )/proc/modules A tool for rendering the contents of a file as more readable content .
The /proc/modules The file is a 0 Byte virtual file , When using, for example cat or When viewing vi, It will contain ( Or better present ) Currently available for lsmod On the executing system Linux List of kernel modules .
Let's first check /proc/modules Whether the contents of the file exist AHCI( Advanced host controller interface )Linux The kernel module :
cat /proc/modules | grep ahci
Here we use cat To display ( Rendering ) The content of /proc/modules, then grep be used for AHCI Modular grep. Please note that , We didn't specify -i Options ( It does a case insensitive search ) To grep, Because the complete list of modules /proc/modules Only lowercase .
We can see the currently available... From the output provided AHCI Linux The kernel module . otherwise , The output looks a little mysterious and less descriptive . Let us lsmod Now try .
lsmod | grep -E '^Module|ahci'
ad locum , We use lsmod A tool without options , be used for grep Get multiple results of interest . The -E Option grep So that we can , The choice of projects we want to see / Selection list ( strand ), All separations consist of one or more pipe symbols (|).
therefore , We're looking for anything here ahci appear ( In the second selector / Select... In the string ) And anything Module appear ( In the first selector / Select... In the string ), among It's a regular expression ( Applies only to the first selector ), Choose start a line, Means we just want to see the beginning of the line followed by “Module” The latter result , This will be our first title line .
We see that the output is now well rendered ; first line ( our grep The command is due to ^Module Selector is included ) And the second row and the third row ahci We grep Module selected due to the second selector .
The header column output tells us what each column contains ; The first column is the module name (Module), The second column is bytes (Size), The third column provides the reference count (Used by), Or to put it another way , How many times has the module been referenced ( May be vaguely translated by the kernel into used ).
If the reference count in the third column is zero , It means that although the module “ stay ” Available in the kernel , But not currently used .
Tips : If you -2 stay See in the output of lsmod, You may need to be in Stackexchange Of “Used by” Check in column lsmod Show -2.
Use modinfo Dig deep
although lsmod Does the tool have its own options , We can combine other utilities with lsmod Discovery information modinfo.
modinfo ahci -F 'description'
modinfo ahci -F 'author'
Here we use the modinfo Command to find information about ahciLinux Kernel More about modules . especially , We use -F Option to modinfo Select the specific fields we want to know about . Please note that , If you are in modinfo ahci Execute without any options , You will see about ahci A complete list of all available information for the kernel module . This is a very verbose output , Because it includes signature key data, etc .
We can grep Use a similar method to select two pieces of information in a single command as before . So , We use modinfo ahci | grep -E ‘description|author’, It presents the same output of two lines , Although directly under each other .
Attention, please. , You can use regular expressions again ’ Select only the output string starting from the beginning of the line ( For the two fields being searched ), namely modinfo ahci | grep -E ‘description|author’
And comparison lsmod,modinfo There are other options you might be interested in . Check out man modinfo To see all available options .
wrap up
In this paper , We discussed no options lsmod Tools and their convenient output for us , Show us what Linux Kernel modules are available and each such kernel module is currently referenced by the kernel (“ Use ”) How many times . We also studied how to use modinfoLinux The commands in get more information about a specific module . We also studied how to grep -E Get two pieces of information at a time by scanning with multiple selection strings .
copyright notice
author[mikes zhang],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270121248217.html
The sidebar is recommended
- Spring IOC container loading process
- [thinking] the difference between singleton mode and static method - object-oriented programming
- Hadoop environment setup (MySQL environment configuration)
- 10 minutes, using node JS creates a real-time early warning system for bad weather!
- Git tool
- Force deduction algorithm - 92 Reverse linked list II
- What is the sub problem of dynamic programming?
- C / C + +: static keyword summary
- Idea does not have the artifacts option when configuring Tomcat
- Anaconda can't open it
guess what you like
-
I don't know how to start this
-
Matlab simulation of transportation optimization algorithm based on PSO
-
MySQL slow log optimization
-
[Vue] as the window is stretched (larger, smaller, wider and higher), the text will not be displayed
-
Popular Linux distributions for embedded computing
-
Suzhou computer research
-
After installing SSL Certificate in Windows + tomcat, the domain name request is not successful. Please answer!!
-
Implementation time output and greetings of jQuery instance
-
The 72 year old uncle became popular. Wu Jing and Guo fan made his story into a film, which made countless dreamers blush
-
How to save computer research
Random recommended
- Springboot implements excel import and export, which is easy to use, and poi can be thrown away
- The final examination subjects of a class are mathematical programming, and the scores are sorted and output from high to low
- Two pronged approach, Tsinghua Professor Pro code JDK and hotspot source code notes, one-time learning to understand
- C + + recursive knapsack problem
- The use of GIT and GitHub and the latest git tutorial are easy to understand -- Video notes of crazy God speaking
- PostgreSQL statement query
- Ignition database test
- Context didn't understand why he got a high salary?, Nginxfair principle
- Bootstrap switch switch control user's guide, springcloud actual combat video
- A list that contains only strings. What other search methods can be used except sequential search
- [matlab path planning] multi ant colony algorithm grid map path planning [including GUI source code 650]
- [matlab path planning] improved genetic algorithm grid map path planning [including source code phase 525]
- Iinternet network path management system
- Appium settings app is not running after 5000ms
- Reactnative foundation - 07 (background image, status bar, statusbar)
- Reactnative foundation - 04 (custom rpx)
- If you want an embedded database (H2, hsql or Derby), please put it on the classpath
- When using stm32g070 Hal library, if you want to write to flash, you must perform an erase. If you don't let it, you can't write continuously.
- Linux checks where the software is installed and what files are installed
- SQL statement fuzzy query and time interval filtering
- 69. Sqrt (x) (c + + problem solving version with vs runnable source program)
- Fresh students are about to graduate. Do you choose Java development or big data?
- Java project: OA management system (java + SSM + bootstrap + MySQL + JSP)
- Titanic passenger survival prediction
- Vectorization of deep learning formula
- Configuration and use of private image warehouse of microservice architect docker
- Relearn JavaScript events
- For someone, delete return 1 and return 0
- How does Java dynamically obtain what type of data is passed? It is used to judge whether the data is the same, dynamic data type
- How does the database cow optimize SQL?
- [data structure] chain structure of binary tree (pre order traversal) (middle order traversal) (post order traversal) (sequence traversal)
- Webpack packaging optimization solution
- 5. Operation element
- Detailed explanation of red and black trees
- redhat7. 9 install database 19C
- Blue Bridge Cup notes: (the given elements are not repeated) complete arrangement (arrangement cannot be repeated, arrangement can be repeated)
- Detailed explanation of springboot default package scanning mechanism and @ componentscan specified scanning path
- How to solve the run-time exception of test times
- Detailed explanation of k8s management tool kubectl
- Android system view memory command