2

Using the C programming language, what is the best way to make a multicore Red Hat Linux processor, use only one core in a test application?

Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187
Frank
  • 1,406
  • 2
  • 16
  • 42

1 Answers1

7

There is a Linux system call specifically for this purpose called sched_setaffinity

For example, to run on CPU 0:

#include <sched.h>
int main(void)
{
    cpu_set_t  mask;
    CPU_ZERO(&mask);
    CPU_SET(0, &mask);
    result = sched_setaffinity(0, sizeof(mask), &mask);
    return 0;
}
Community
  • 1
  • 1
Gearoid Murphy
  • 11,834
  • 17
  • 68
  • 86