- /*
- * linux_test_for_realtime_kernel1.c - simple test whether the
- * current Linux kernel is a realtime kernel
- *
- * Written by Roland Mainz <roland.mainz@nrubsig.org>
- */
- #include <stdlib.h>
- #include <stdbool.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <errno.h>
- #include <string.h>
- /*
- * EINTR_REPEAT - make sure we repeat aborted syscalls since
- * we cannot rely on |SA_RESTART| in library code
- */
- #define EINTR_REPEAT(expr) \
- { while((expr) && (errno == EINTR)) errno=0; };
- int linux_is_realtime_kernel(void)
- {
- int fd;
- /*
- * Lazy buffer sizing. Instead of |fstat()| on fd or
- * loop on |read()| we just assume that the contents
- * of "/proc/sys/kernel/version" have always a size
- * less than 1k.
- */
- char buff[1024];
- ssize_t s;
- int res = 0;
- EINTR_REPEAT(fd = open("/proc/sys/kernel/version",
- O_RDONLY|O_CLOEXEC));
- if (fd == -1) {
- perror("Cannot open /proc/sys/kernel/version");
- return -1;
- }
- EINTR_REPEAT(s = read(fd, buff, sizeof(buff)-1));
- if (s > 0) {
- buff[s] = '\0';
- if (strstr(buff, "PREEMPT_RT"))
- res = 1;
- }
- (void)close(fd);
- return res;
- }
- int main(int ac, char *av[])
- {
- int x;
- (void)puts("#start.");
- x = linux_is_realtime_kernel();
- (void)printf("kernel a realtime-kernel = %d\n", x);
- (void)puts("#done.");
- return EXIT_SUCCESS;
- }
linux_test_for_realtime_kernel1.c - simple test whether the current Linux kernel is a realtime kernel
Posted by Anonymous on Mon 6th Mar 2023 13:04
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.