Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Quick and dirty listing of CPU used, grouped by process with the same name (maybe different pid or even path!)
- IFS=$'\n'
- foundheader=0
- unset foundNames
- declare -A foundNames
- for line in $(top -b -n 1); do
- if echo "$line" | grep "PID.*USER.*PR"; then
- foundheader=1
- continue
- fi
- if [ $foundheader = 0 ]; then
- continue
- fi
- #echo "line is $line"
- name=$(echo "$line" | awk '{print $12}')
- cpu=$(echo "$line" | awk '{print $9}')
- oldCpu=${foundNames["$name"]}
- let newCpu=cpu+oldCpu
- #echo "name $name, cpu $cpu, oldCpu $oldCpu, newCpu $newCpu"
- foundNames["$name"]="$newCpu"
- done
- for key in ${!foundNames[@]}; do
- value=${foundNames[$key]}
- if [ "$value" = 0 ]; then
- continue
- fi
- printf "%2d%% %s\n" "${value}" "$key"
- done | sort -rn
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement