LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   LINUX_VERSION_CODE in c (https://www.linuxquestions.org/questions/programming-9/linux_version_code-in-c-937024/)

ankitm 03-29-2012 02:58 AM

LINUX_VERSION_CODE in c
 
Hi,
My Linux version is
Linux 2.6.9-42.ELsmp
I am printing the value of LINUX_VERSION_CODE in c program which comes out to be 132116.

I also tried to get the value by KERNEL_VERSION(2,6,9) which is 132617 as [(2 << 16)+(6<<8)+9 ] .

Does LINUX_VERSION_CODE and KERNEL_VERSION(2,6,9) calculates value differently ?

Please correct me if I am wrong as I am understanding LINUX_VERSION_CODE and KERNEL_VERSION(2,6,9) .

Thanks

jhwilliams 03-29-2012 03:15 AM

You can see these definitions in the top level Makefile of the Linux source tree. I pulled these from a 3.x series kernel source:

Code:

986 define filechk_version.h
 987    (echo \#define LINUX_VERSION_CODE $(shell                            \
 988    expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL));    \
 989    echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';)
 990 endef

But anyway, your program is probably printing the user-space value defined in /usr/include/linux/version.h. So what's in there? 132116 ? On my system, the value is equivalent to 3.0.14, which is NOT the running kernel version. Rather, it is the version associated with the Linux headers when they got installed. I have since moved on to 3.0.16, but no one (not a package nor me) has updated the headers, I guess.

Particularly, an update to that file (<linux/version.h>) would result from running a make headers_install in the linux source tree.

NevemTeve 03-30-2012 11:06 AM

uname(2) is your friend


All times are GMT -5. The time now is 04:11 AM.