Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写使用 sched_setaffinity 的代码,它需要内核 2.5.8 或更高版本。我一直在试图找出这些事情是否可能:
我想我的问题是,如何在使用旧系统时安全地使用新内核函数,而不破坏整个应用程序?
使用dlopen()withNULL作为文件名,以及dlsym()您要使用的功能。如果dlsym()成功,则通过返回的函数指针调用该函数。
dlopen()
NULL
dlsym()
您是否试图让您的程序链接或运行?您可以直接通过 glibc 函数调用系统调用,syscall()而无需最近的 C 库。显然,在没有支持的早期系统上它会失败(快速测试显示内核为未实现的系统调用号返回 -1 == ENOSYS),因此您需要对此进行测试。
syscall()