cancel
Showing results for 
Search instead for 
Did you mean: 
Create a Post
Highlighted

ONELINER - process utilization per core

Jump to solution

With this onliner you can view the process load of each core.
Change the variable CORE to the correct core number (for example CORE=3):

 

CORE=3; ps --sort=-c -e -o pid,psr,%cpu,%mem,cmd | grep -E  "^[[:space:]][[:digit:]]+[[:space:]]+${CORE}"

 

ps L       -> List all format specifiers (for example pid, psr, %cpu, %mem, ...)

ps_core_2.jpg

There is still much potential for improvement here 🙂

1 Solution

Accepted Solutions
Highlighted

Re: ONELINER - process utilization per core

Jump to solution

I always use this one:

 

watch -n 1 'CORE=2; ps --sort=-c -e -o pid,psr,%cpu,%mem,wchan,vsize,time,cmd | grep -E  "^[[:space:]][[:digit:]]+[[:space:]]+${CORE}"'

 

> Refresh display every second
> For core two (set CORE=x parameter)
> Is sorted by CPU load
> The following fields are used:
   - Process ID
   - Core
   - CPU utilization in %
   - Memory utilization in %
   - Process type
   - Process memory usage in KB
   - Process time
   - Process path+command

Output:

onliner_ps_1.JPG

If you want to sort it by memory usage, use this:

 

watch -n 1 'CORE=2; ps --sort=-vsize -e -o pid,psr,%cpu,%mem,wchan,vsize,time,cmd | grep -E  "^[[:space:]][[:digit:]]+[[:space:]]+${CORE}"'

 

View solution in original post

Tags (1)
5 Replies
Highlighted

Re: ONELINER - process utilization per core

Jump to solution

I always use this one:

 

watch -n 1 'CORE=2; ps --sort=-c -e -o pid,psr,%cpu,%mem,wchan,vsize,time,cmd | grep -E  "^[[:space:]][[:digit:]]+[[:space:]]+${CORE}"'

 

> Refresh display every second
> For core two (set CORE=x parameter)
> Is sorted by CPU load
> The following fields are used:
   - Process ID
   - Core
   - CPU utilization in %
   - Memory utilization in %
   - Process type
   - Process memory usage in KB
   - Process time
   - Process path+command

Output:

onliner_ps_1.JPG

If you want to sort it by memory usage, use this:

 

watch -n 1 'CORE=2; ps --sort=-vsize -e -o pid,psr,%cpu,%mem,wchan,vsize,time,cmd | grep -E  "^[[:space:]][[:digit:]]+[[:space:]]+${CORE}"'

 

View solution in original post

Tags (1)
Highlighted
Employee+
Employee+

Re: ONELINER - process utilization per core

Jump to solution

Really like this one-liner, made a small change to have it run over all cores and sort by CPU usage or Memory usage:

Sort by CPU:

echo "" > coreload.txt ; for (( cpuCore = 0; cpuCore < $(cpstat os -f cpu | grep Number: | awk '{print $3}'); ++cpuCore )); do CORE=${cpuCore}; ps -e -o pid,psr,%cpu,%mem,cmd | grep -E "^[[:space:]][[:digit:]]+[[:space:]]+${CORE}" >> coreload.txt; done ; cat coreload.txt | sort -k3 -gr

Sort by Memory:

echo "" > coreload.txt ; for (( cpuCore = 0; cpuCore < $(cpstat os -f cpu | grep Number: | awk '{print $3}'); ++cpuCore )); do CORE=${cpuCore}; ps -e -o pid,psr,%cpu,%mem,cmd | grep -E "^[[:space:]][[:digit:]]+[[:space:]]+${CORE}" >> coreload.txt; done ; cat coreload.txt | sort -k4 -gr
Highlighted

Re: ONELINER - process utilization per core

Jump to solution

Hi @KernelGordon,

You can use this! It is quick and easy:

ps --sort=-c -e -o pid,psr,%cpu,%mem,wchan,vsize,time,cmd
ps --sort=-vsize -e -o pid,psr,%cpu,%mem,wchan,vsize,time,cmd

You can sort directly into ps with "--sort". If you use a "--sort=-" it will sort in reverse order 🙂

0 Kudos
Highlighted

Re: ONELINER - process utilization per core

Jump to solution

Or just to monitor the firewall workers

watch -n 1 'ps --sort=-c -e -o pid,psr,%cpu,%mem,wchan,time,cmd |grep "fw_worker_"|grep -v pipe|grep -v grep '

Output:

firewall_worker_1.JPG

0 Kudos
Employee+
Employee+

Re: ONELINER - process utilization per core

Jump to solution

Nice find! I wasn't aware of the 'psr' format specifier. Time to read the man page and see if there are any other neat things to add to this 😀