How to safely use the new Linux features?

I am writing code that uses sched_setaffinity, which requires a kernel of 2.5.8 or later. I tried to find out if this is possible:

  • Systems with older kernels to compile this gracefully, perhaps just completely ignoring this segment of code.
  • If I send someone with an older kernel a compiled binary, it will switch to this function or just print a warning.

I assume that my question is, how do you safely use the new kernel functions without breaking the application on the old system?

+6
source share
2 answers

Are you trying to connect or run your program? You can call a system call directly through the glibc syscall() function without requiring the recent C library. Obviously, this will crash on earlier systems without support (a quick test shows that the kernel returns -1 == ENOSYS for unrealized numbers syscall), so you will need to check this out.

+2
source

Use dlopen() with NULL as the file name and dlsym() function you want to use. If dlsym() succeeds, call the function using the return function pointer.

+3
source

Source: https://habr.com/ru/post/916499/


All Articles