For example
the following code will bind the main thread/process to cpu No. 0
#define _GNU_SOURCE
#include
void run_on_cpu(int cpu)
{
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(cpu,&mask);
sched_setaffinity(0,sizeof(cpu_set_t),&mask);
}
main()
{
run_on_cpu(0);
while(1);
}
No comments:
Post a Comment