Created
October 25, 2017 07:02
-
-
Save ryanwoodsmall/be00c6b191f6459782dea1516020e91c to your computer and use it in GitHub Desktop.
get linux kernel version from linux/version.h header and uname() syscall
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <linux/version.h> | |
#include <sys/utsname.h> | |
/* | |
* from rhel7's linux/version.h: | |
* #define LINUX_VERSION_CODE 199168 | |
* #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) | |
*/ | |
int main(void) | |
{ | |
int maj = LINUX_VERSION_CODE >> 16; | |
int min = ( LINUX_VERSION_CODE - ( maj << 16 ) ) >> 8; | |
int pat = LINUX_VERSION_CODE - ( maj << 16 ) - ( min << 8 ); | |
struct utsname unamedata; | |
printf("linux/version.h : %d = %d.%d.%d\n", LINUX_VERSION_CODE, maj, min, pat); | |
uname(&unamedata); | |
printf("uname : utsname.release = %s\n", unamedata.release); | |
return(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment