get current core id
Tue Jun 1 07:50:00 GMT 2010
> > Does anyone know if it is possible to get the ID of the core which is
> > executing code at a given point in a C++ program? I'm running code built
> > using gcc 4.4.1 on Ubuntu Koala 64-bit with an Intel core 2 quad and would
> > like to see whether external code calling a function in a shared library is
> > making use of multiple cores.
> This isn't a gcc question. The compiler doesn't know anything about
> different cores. I say this not to chastise you, but to let you know
> that you are more likely to get the answer if you ask on a more
> appropriate forum. The answer may be operating system specific.
I don't know a system-independent solution, however on Linux the easiest
way is probably to read it from /proc/PID/stat. It should be the
column 39 (?) - see "man 5 proc":
processor %d (since Linux 2.2.8)
CPU number last executed on.
But I'm not sure whether you can get this information also for multiple
threads sharing the same process-ID? That might depend on the threading
More information about the Gcc-help