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?
            Asked
            
        
        
            Active
            
        
            Viewed 212 times
        
    2
            
            
         
    
    
        Kiril Kirov
        
- 37,467
- 22
- 115
- 187
 
    
    
        Frank
        
- 1,406
- 2
- 16
- 42
1 Answers
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
- 
                    @Gearoid Murphy, Thank you for your answer. I will test it one hour and award you one Stack Overflow point and aceept your answer. – Frank Sep 18 '13 at 11:24
- 
                    1Note: `int main(void)` – wildplasser Sep 18 '13 at 11:37