pthread_setaffinity_np与sched_setaffinity的区别:sched_setaffinity可在进程的线程中去修改亲和性
写在启动脚本中是使用pthread_setaffinity_np、sched_setaffinity、还是tasklet ? (https://www.cnblogs.com/x_wukong/p/5924298.html)
c语言如何调用到系统命令reboot ?
同时在使用时我们会有一些初始化的操作: void CPU_ZERO(cpu_set_t *set);(初始化操作) void CPU_SET(int cpu,cpu_set_t *set)(将某个cpu加进cpu集里) void CPU_CLR(int cpu,cpu_set_t *set)(将某个cpu清除出cpu集里) void CPU_ISSET(int cpu,const cpu_set_t *set)(判断某个cpu是不是在cpu集里) #define _GNU_SOURCE #include <stdio.h> #include <pthread.h> #include <unistd.h> #include <sys/reboot.h> cpu_set_t cpuset,cpuget; void *thread_func(void *param) { CPU_ZERO(&cpuset); CPU_SET(1, &cpuset); /* cpu 1 is in cpuset now */ /* bind process to processor 1 */ if (pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset) !=0) { printf("pthread_setaffinity_np error\n"); } while(1) { if() { sync(); sync(); sync(); reboot(RB_AUTOBOOT); } } pthread_exit(NULL); } int main(int argc, char *argv[]) { pthread_t my_thread; if (pthread_create(&my_thread, NULL, thread_func,NULL) != 0) { printf("pthread_create error \n"); } pthread_join(my_thread,NULL); return 0; }
————————————————
版权声明:本文为CSDN博主「jsdchenye」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/jsdchenye/article/details/44703615