example:
#include <stdio.h>
#include <utmpx.h>
int main()
{
int c, s;
int cpu;
cpu = sched_getcpu();
printf("id=%d\n", cpu);
return 0;
}
Ps. linux version > 2.6.19
references:
How can I get the CPU core number from within a user-space app (Linux, C)?
INTEL DOC