Linux???????????CPU
???????????? ???????[ 2015/5/6 13:50:04 ] ??????????????
????????ó?????и?????????????????????????????????????CPU?????????????????????????????????????
???????????CPU
????Linux??????????????????????????CPU??
????#include <sched.h>
????int sched_setaffinity(pid_t pid?? size_t cpusetsize?? const cpu_set_t *mask);
????int sched_getaffinity(pid_t pid?? size_t cpusetsize?? cpu_set_t *mask);
????????
????pid???????id??????pid?0????????????
????cpusetsize??mask???С
????mask?????н????CPU????????????o???????mask
????#define CPU_SET(cpu?? cpusetp) //????cpu
????#define CPU_CLR(cpu?? cpusetp) //???cpu
????#define CPU_ISSET(cpu?? cpusetp) //?ж?cpu
????#define CPU_ZERO(cpusetp) //??????0
???????????
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include <sched.h>
void WasteTime()
{
int abc = 10000000;
while(abc--)
{
int tmp = 10000*10000;
}
sleep(1);
}
int main(int argc?? char **argv)
{
cpu_set_t mask;
while(1)
{
CPU_ZERO(&mask);
CPU_SET(0?? &mask);
if (sched_setaffinity(0?? sizeof(mask)?? &mask) < 0) {
perror("sched_setaffinity");
}
WasteTime();
CPU_ZERO(&mask);
CPU_SET(1?? &mask);
if (sched_setaffinity(0?? sizeof(mask)?? &mask) < 0) {
perror("sched_setaffinity");
}
WasteTime();
CPU_ZERO(&mask);
CPU_SET(2?? &mask);
if (sched_setaffinity(0?? sizeof(mask)?? &mask) < 0) {
perror("sched_setaffinity");
}
WasteTime();
CPU_ZERO(&mask);
CPU_SET(3?? &mask);
if (sched_setaffinity(0?? sizeof(mask)?? &mask) < 0) {
perror("sched_setaffinity");
}
WasteTime();
}
}
????????
??????????????г???????????top -p ????id??????f??????j???????????????????????cpu0123?????л???
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11