Not the best in C programming, here is my first trial to port a program from python to C. Credits to Alnitak for the program below
#include<sched.h>
void task_set(int pid) {
int result;
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(pid, &mask);
result = sched_setaffinity(0, sizeof(mask), &mask);
printf ("%d\n",result);
}
void main()
{ //excuse me for the static
task_set(1400);
}
To compile I did this..
gcc -D_GNU_SOURCE -o test test.c
However, when I try to go back and check where the program is running using the following script:
def which_core(pid):
f = file(os.path.join('/proc', str(fpid), 'stat'), 'rb')
val = f.read()
f.close()
return int(val.split(' ')[-6])
print 'core_id',which_core(1400)
It gives me the following output:
core_id 32997376
It is quite confusing there... what is the mistake?