Find the answer to your Linux question:
Results 1 to 4 of 4
Hi! In the application I am developing I need to check the kernel version currently running to know which file I can include (specifically if POSIX message queues are implemented ...
  1. #1
    Just Joined!
    Join Date
    Mar 2007
    Posts
    6

    Discrepancy between uname -r and /usr/include/linux/version.h

    Hi!

    In the application I am developing I need to check the kernel version currently running to know which file I can include (specifically if POSIX message queues are implemented on the platform or if the program should use IPC).
    Unfortunately there is a discrepancy between the /usr/include/linux/version.h and the real installed kernel.

    > uname -r
    2.6.9-42.ELsmp

    > more /usr/include/linux/version.h
    #define UTS_RELEASE "2.4.20"
    #define LINUX_VERSION_CODE 132116
    (...)

    Which means that the application thinks kernel 2.4 is running whereas it is really 2.6.9.

    What is the correct way to get the kernel version from a program? Or at least is there another way to know what is available on the running machine? I thought may be through the version of the glibc library but I need to determine this at compilation time and can't find a way to do this...

    Anne

  2. #2
    Linux User
    Join Date
    Oct 2004
    Location
    /dev/random
    Posts
    404
    The files put under /usr/include are not kernel headers, but glibc headers (it has part of kernel headers for interfacing with kernel - albeit they're not the same as the headers used for kernel compilation).

    The correct way to find out the running kernel version from C code is by using the uname() system call - use man 2 uname or uname manpage here.

    HTH
    The Unforgiven
    Registered Linux User #358564

  3. #3
    Just Joined!
    Join Date
    Mar 2007
    Posts
    6
    What I wanted to do is discover the running kernel version at compilation time and depending on the value include different parts of my code. For example in kernel2.6 POSIX message queues are implemented whereas if I have a 2.4 I must use IPC.
    Is there a way to discover at compilation time what is available or not?

    Anne

  4. #4
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    I'm sure this is possible with Makefiles but I have never set one up, sorry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...