you can use ps .
for example with a python process with two busy threads on a dual core processor:
$ ps -p 29492 -L -o pid,tid,psr,pcpu PID TID PSR %CPU 29492 29492 1 0.0 29492 29493 1 48.7 29492 29494 1 51.9
(PSR is the identifier of the CPU to which the thread is currently assigned)
you see that threads are running on the same processor core (due to GIL)
works with the same python script in jython, we see that the script uses both cores (and there are many other services or any threads that are almost idle):
$ ps -p 28671 -L -o pid,tid,psr,pcpu PID TID PSR %CPU 28671 28671 1 0.0 28671 28672 0 4.4 28671 28673 0 0.6 28671 28674 0 0.5 28671 28675 0 2.3 28671 28676 0 0.0 28671 28677 1 0.0 28671 28678 1 0.0 28671 28679 0 4.6 28671 28680 0 4.4 28671 28681 1 0.0 28671 28682 1 0.0 28671 28721 1 0.0 28671 28729 0 88.6 28671 28730 1 88.5
You can process the output and calculate a common processor for each CPU core.
Unfortunately, this approach does not seem to be 100% reliable, sometimes I see that in the first case, two worker threads are reported to be shared on each CPU core, or in the latter case, two threads are reported to be on the same core.
mykhal Oct 11 2018-10-10 21:39
source share