This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: get current core id


Hello,
> 
> > 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
library used.

Axel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]