Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-29-2012, 02:58 AM   #1
Registered: Sep 2011
Posts: 33

Rep: Reputation: Disabled

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) .

Old 03-29-2012, 03:15 AM   #2
Senior Member
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
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:

 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.

Last edited by jhwilliams; 03-29-2012 at 03:18 AM.
Old 03-30-2012, 11:06 AM   #3
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,240

Rep: Reputation: 981Reputation: 981Reputation: 981Reputation: 981Reputation: 981Reputation: 981Reputation: 981Reputation: 981
uname(2) is your friend


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:23 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration