Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a macro definition to check the Linux kernel version?

I'm wondering if there is a gcc macro that will tell me the Linux kernel version so I can set variable types appropriately. If not, how would I go about defining my own macro that does this?

like image 724
zztops Avatar asked May 23 '13 18:05

zztops


People also ask

How can the version of the Linux kernel be checked?

To check Linux Kernel version, try the following commands: uname -r : Find Linux kernel version. cat /proc/version : Show Linux kernel version with help of a special file. hostnamectl | grep Kernel : For systemd based Linux distro you can use hotnamectl to display hostname and running Linux kernel version.

Where is Linux_version_code defined?

As to your question : the value of LINUX_VERSION_CODE comes from /usr/include/linux/version. h as a standard location.

Is Linux version and kernel version same?

So now,simply you can say Linux is a kernel. Linux + shell(Bash,Gnome etc) is a Linux distro say Ubuntu,Mint,Kali etc and each of them is a OS. Show activity on this post. "kernel" and "shell" are the original terms, as in let's say "core" and "shell".


1 Answers

The linux/version.h file has a macro called KERNEL_VERSION which will let you check the version you want against the current linux headers version (LINUX_VERSION_CODE) installed. For example to check if the current Linux headers are for kernel v2.6.16 or earlier:

#include <linux/version.h>  #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,16) ... #else ... #endif 

A better way to get the version information at run-time is to use the utsname function in include/linux/utsname.h.

char *my_kernel_version = utsname()->release; 

This is essentially how /proc/version gets the current kernel verison.

See also

Getting kernel version from linux kernel module at runtime

like image 56
Vilhelm Gray Avatar answered Sep 20 '22 09:09

Vilhelm Gray