Per customer requirements, I installed CentOS 5.6 with the default kernel. With this kernel installed, the time.h file includes the #define CLOCK_MONOTONIC.

Now, a real-time kernel was installed along with the kernel-devel and our code would like to use CLOCK_MONOTONIC_RAW. It does exist as a part of the kernel's header files, but when I compile our code, it does not find it in the standard userspace includes.

My question is, what is the proper procedure to including/replacing the time.h found by default with the real-time kernel? From my research, it looks like symlinks are bad, so how should it be handled? What is the procedure or process? Upgrading to CentOS 6.0 or 5.7 is not an option per customer requirements.

  • Are you planning on inserting this module into the default CentOS kernel? – bahamat Jul 18 '12 at 16:11

There's a key distinction to be made about where header files come from:

  • <time.h> is provided by glibc (e.g. the glibc-headers package)
  • <linux/time.h> is provided by the Linux kernel headers.

Changing the kernel and its header packages will not affect <time.h>. Only changing glibc will do that.

You should find that glibc's <time.h> includes <bits/time.h> which resolves as e.g. /usr/include/x86_64-linux-gnu/bits/time.h and defines CLOCK_MONOTONIC_RAW. If it doesn't, and you can't upgrade it, then you'll have to resort to including code like this:

#include <time.h>

You just need to #include <linux/time.h>

  • Thank you for the response. I checked the linux/time.h location and it too does not have a reference to "RAW". I am running an updated real-time kernel, but I just need to understand how to transfer the new kernel's headers that does have a reference to "RAW" into the userspace header files. Am I making any sense or is my approach correct? Thank you again for the help. – cabanaboy Jan 5 '12 at 16:05
  • @cabanaboy, I'm not sure where you are looking or where the file came from, but linux/time.h most certainly should define CLOCK_MONOTONIC_RAW. It also doesn't matter whether you are running a real-time kernel or not; the headers are the same. – psusi Jan 5 '12 at 21:47
  • 3
    @cabanaboy, wait... you're running an old os that must have shipped with a kernel older than 2.6.28 when that was added. How did you get the new kernel installed? If you built it from source yourself, then you need to make install_headers. If you got an updated kernel package, then you need to get the corresponding updated kernel_headers package. – psusi Jan 5 '12 at 21:53

The headers that your distribution installs are not the ones in the kernel, they are sanitzed/"userspaced" versions. You'd have to get a copy of the headers in include/linux in the kernel sources and set up so they are used in preference to the ones in /usr/include/linux (need to frob the -I flag for gcc). And check if nothing misfires.


I would make sure I'm building against the headers that came with the new kernel. CLOCK_MONOTONIC_RAW should be defined in linux/time.h. First find out which headers you are using, and check how its defined in the file. You can define it in your code ( only as a check ) to see what happens.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.