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
  • 36,509
  • 22
  • 109
  • 183
Frank
  • 1,376
  • 2
  • 14
  • 41

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,387
  • 17
  • 65
  • 86