2

What is the command to find out number of cores the process is running on at any instance ?

-Thanks

Ashish singhi
  • 121
  • 1
  • 1
  • 2

1 Answers1

1

Top command can provide information on individual threads of a process using the following command

top -H -p <pid>

To find the last core on which the thread was run try press f, than press j to enable the CPU core column.

Output will be like

top - 11:50:35 up 332 days, 16:31,  2 users,  load average: 1.39, 1.45, 1.31
Tasks:   7 total,   1 running,   6 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.8%us,  1.7%sy,  0.0%ni, 95.5%id,  0.0%wa,  0.0%hi,  0.1%si,  0.0%st
Mem:  65980588k total, 24549232k used, 41431356k free,    30268k buffers
Swap: 135170856k total, 23016712k used, 112154144k free, 11289596k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+   P COMMAND
10721 tom       25   0  326m 285m 3536 R 100.0  0.4 182:13.73 22 kproxy
10722 tom       17   0  326m 285m 3536 S  0.0  0.4   0:00.00  0 kproxy
10723 tom       15   0  326m 285m 3536 S  0.0  0.4   0:00.15  7 kproxy
10724 tom       15   0  326m 285m 3536 S  0.0  0.4   0:00.00  1 kproxy
10722 tom       17   0  326m 285m 3536 S  0.0  0.4   0:00.00  0 kproxy
10723 tom       15   0  326m 285m 3536 S  0.0  0.4   0:00.15  7 kproxy
10724 tom       15   0  326m 285m 3536 S  0.0  0.4   0:00.00  1 kproxy

Numbers below the P column is the core that was last used by the thread. Value R below the S column means that thread is running.

Deven
  • 301
  • 2
  • 8
  • Actually I wanted the maximum number of cores on which the process can run, not the core number on which the process was last ran. – Ashish singhi Feb 21 '14 at 04:01
  • 3
    I got the solution for this. We can execute following command to get to know the total number of cores on which the process is running at that instance. "**ps -eL -o pid,lwp,cpuid | grep | awk '{print $3}' | sort -u | wc -l**" – Ashish singhi Feb 21 '14 at 04:02
  • @Ashish I tried "ps -eL -o pid,lwp,cpuid | grep | awk '{print $3}'" and found that you will get CPU id on which the thread is running or was last running. Doing the Sort -u you eliminate the duplicates so that you get a unique number of cores on which threads were running or last running. Many of these threads may be sleeping when you get the output. your results are very scheduler dependent and on a different server or on a different time on the same server you may get different results – Deven Feb 21 '14 at 06:52
  • You mean this command is not trust full to find out the number of cores on which the process is running at any one point of time ? – Ashish singhi Feb 22 '14 at 06:41
  • For what purpose do you need number of cores used by the process? – Deven Feb 23 '14 at 06:54
  • To calculate the cpu used by a process (in terms of %) at an instance. – Ashish singhi Feb 24 '14 at 05:06
  • CPU utilization(for eg from top) is a more stable indicator, which I think you should use.Distribution of threads on cores is a decision of process scheduler in OS. There are many factors that can change the distribution for eg number of cores per processor, NUMA architecture etc. On a 8 core machine with 2 processor or the 12 core machine with 2 processor you can get very different distribution of threads on cores for the same process and scenario.Point is that there are many factors and this indicator of number of cores on which the threads are running and last ran is not a stable indicator. – Deven Feb 24 '14 at 05:59