multicore - How can I get the CPU core number from within a user-space app (Linux, C)? -


presumably there library or simple asm blob can me number of current cpu executing on.

use sched_getcpu determine cpu on calling thread running. see man getcpu (the system call) , man sched_getcpu (a library wrapper). however, note says:

the information placed in cpu guaranteed current @ time of call: unless cpu affinity has been fixed using sched_setaffinity(2), kernel might change cpu @ time. (normally not happen because scheduler tries minimize movements between cpus keep caches hot, possible.) caller must prepared handle situation when cpu , node no longer current cpu , node.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -