0
votes

I have made an application in c which creates 4 threads. How can I check which thread is running on which core through terminal and through code.

1
Normally, the OS distributes threads to the different CPUs, so any CPU that it's running on right now may or may not be the same CPU it's running on in a millisecond. However, you can control thread affinity with POSIX threads, which Linux supports, or you can use e.g. a tool like htop to assign threads/processes to CPUs. - Ulrich Eckhardt
@SergeiKulik pthread_getaffinity_np() is always returning 0, even though I am setting affinity using pthread_setaffinity_np(). - Barinder Grewal
What does the manpage have to say about that particular returnvalue? - Ulrich Eckhardt

1 Answers

1
votes

I found the answer about how to check it using terminal.
/home# for i in $(pgrep applicationName); do ps -mo pid,tid,fname,user,psr -p $i;done