Multiple multi-core CPUs are now the mainstream servers. Many applications, such as Squid and nginx, have the ability to distribute processes or threads to different CPU cores.
How can we view the distribution of different processes in the CPU core.
Use the top tool and use the pgrep or pidof commands.
For example, to view the distribution of CPU cores in the nginx process:
- Top-p $ (pgrepnginx | awk 'in in {ORS = ","} {print $0} '| sed's/. $ //')
- # Or you can use
- # Pidof nginx | sed-e's //,/G'
- # To replace
- # Pgrepnginx | awk 'in in {ORS = ","} {print $0} '| sed's/. $ //'
- # To obtain the formatted pid Value
Press the f key to list the display menu options, press j, and select the CPU core information column. Press enter to return to the top screen.
As follows:
- Top-14: 46: 21up13: 45, 2 users, loadaverage: 0.00, 0.00, 0.00
- Tasks: 5 total, 0 running, 5 sleeping, 0 stopped, 0 zombie
- Cpu (s): 0.0% us, 0.1% sy, 0.0% ni, 99.9% id, 0.0% wa, 0.0% hi, 0.0% si, 0.0% st
- Mem: 1026684 ktotal, 887572 kused, 139112 kfree, 135308 kbuffers
- Swap: 2064376 ktotal, 0 kused, 2064376 kfree, 603008 kcached
- Piduserprni1_resshrs % CPU % MEMTIME + PCOMMAND
- 12393root180410001428808S0. 00.10: 00.001 nginx
- 12625nginx150413441440536S0. 00.10: 00.000 nginx
- 12626nginx150413441592688S0. 00.20: 00.001 nginx
- 12627nginx150413441440536S0. 00.10: 00.002 nginx
- 12628nginx150413441440536S0. 00.10: 00.003 nginx