Reputation: 237
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:
I guess my question is, how do you use new kernel functions safely, without breaking the entire application when using an older system?
Upvotes: 6
Views: 176
Reputation: 12043
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.
Upvotes: 2
Reputation: 8674
Use dlopen()
with NULL
as the filename, and dlsym()
the function you want to use. If the dlsym()
succeeds, call the function through the function pointer that was returned.
Upvotes: 3