how can I obtain runtime information about which version of kernel is running from inside linux kernel module code (kernel mode)?
how can I obtain runtime information about which version of kernel is running from
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
By convention, Linux kernel module loading mechanism doesn’t allow loading modules that were not compiled against the running kernel, so the “running kernel” you are referring to is most likely is already known at kernel module compilation time.
For retrieving the version string constant, older versions require you to include
<linux/version.h>, others<linux/utsrelease.h>, and newer ones<generated/utsrelease.h>. If you really want to get more information at run-time, thenutsname()function fromlinux/utsname.his the most standard run-time interface.The implementation of the virtual
/proc/versionprocfs node usesutsname()->release.If you want to condition the code based on kernel version in compile time, you can use a preprocessor block such as:
It allows you to compare against major/minor versions.