Ps on linux (procps) how to check which processor is used

This is the procps package, the ps utility for linux.

Can it print the number of last used CPUs for each process (thread)?

Update: not CPU time (10 seconds), but CPU NUMBER (CPU0, CPU5, CPU123)

+6
source share
3 answers

which of several processors? he does not offer an option for this according to the man page. but on my stable Debian system, it accepts undocumented -o cpu


after looking at the source and output of ps L , I believe that your answer is the output parameters cpuid or sgi_p , CPUID and P, column identifiers, respectively.
And "cpu" should work according to this entry in output.c, but it is currently tied to the output of "nop" pr_nop ():

{"cpu", "CPU", pr_nop, sr_nop, 3, 0, BSD, AN|RIGHT}, /* FIXME ... HP-UX wants this as the CPU number for SMP? */

+3
source

The ps (1) man page says that you can use the psr field:

  psr PSR processor that process is currently assigned to. 
 $ ps -o pid,psr,comm PID PSR COMMAND 7871 1 bash 9953 3 ps 

Or you can use the cpuid field, which does the same.

 $ ps -o pid,cpuid,comm PID CPUID COMMAND 7871 1 bash 10746 3 ps 

The reason for the two names is compatibility with Solaris ( psr ) and NetBSD / OpenBSD ( cpuid ).

To get streams, add the -L option (and the lwp field if you use -o ).

Without threads:

 $ ps -U $USER -o pid,psr,comm | egrep 'chromi|PID' | head -4 PID PSR COMMAND 6457 3 chromium-browse 6459 0 chromium-browse 6461 2 chromium-browse 

With threads:

 $ ps -U $USER -L -o pid,lwp,psr,comm | egrep 'chromi|PID' | head -4 PID LWP PSR COMMAND 6457 6457 3 chromium-browse 6457 6464 1 chromium-browse 6457 6465 2 chromium-browse 

There is also an undocumented -P option that adds psr to normal fields:

 $ ps -U $USER -LP | egrep 'chromi|PID' | head -4 PID LWP PSR TTY TIME CMD 6457 6457 3 ? 00:01:19 chromium-browse 6457 6464 1 ? 00:00:00 chromium-browse 6457 6465 2 ? 00:00:00 chromium-browse 
+16
source

Also significantly underestimated:

 mpstat -I ALL 1 | less -SR 
+3
source

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


All Articles