I’m writing code that uses sched_setaffinity, which requires kernel 2.5.8 or later. I’ve been trying to find out if these things are possible:
- Systems with older kernels to compile this gracefully, perhaps just ignoring that code segment entirely.
- If I send someone with an older kernel a compiled binary, it will step over this function or simply print a warning.
I guess my question is, how do you use new kernel functions safely, without breaking the entire application when using an older system?
Are you trying to get your program to link or to run? You can invoke the system call directly via the glibc
syscall()function without needing a recent C library. Obviously it’s going to fail on earlier systems without support (a quick test shows the kernel returns -1 == ENOSYS for unimplemented syscall numbers), so you will need to test for that.