How to get processor information in Linux?

There are several processors (0-7) on my server. I need to run parallel code, and each process joins one processor, so how do I find out the CPU information for each process?

For example, if there are two processes (# 0 and # 1), and process C # 0 uses CPU 5, and process 7 uses processor 7.

How to find out what programming is in C or Fortran?

+3
source share
5 answers

Use the sched_getcpu () call .

, / /, 1 , 2 - . , sched_setaffinity()

+2

Linux, , . @nos , sched_getcpu() , , .

, /proc. , , , , .

/proc/<pid>/stats , , . . ( man proc, ).

+2

, - . ( , grep ) ​​.

, , .

, / .

?

+1

Typically, you need to change the proximity of the processor because the process can migrate between processors: “Processor Priority” (Linux Journal, 2003).

0
source

More generally, why do you want to know? The Linux kernel is very well suited for scheduling processes / threads to make the best use of the available kernels.

0
source

Source: https://habr.com/ru/post/1757898/


All Articles