This article introduces a method to display the total CPU usage of processes in WSL Linux Bash, a Linux PC/server running on Windows.

I have previously written about checking CPU usage in Windows using the following command.
# Check cpu usage for whole Windows 10 system
calc3 " round ( $( grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}' | chomplastchar ) ) "
But what about a case like this: you want to check CPU usage only for WSL processes.
# Check cpu usage within WSL system
calc3 " round ( ( $( printf -- "%s+" $( ps fux | awk 3 | tail -n +2 ) | chomplastchar ) ) ) "

Functions used:
alias calc3='pythonprint3'
awk ()
{
: e.g. `# something | awk 2 `;
: e.g. `# something | awk nr2 `;
[[ "${1}" =~ ^[0-9]+$ ]] && {
/usr/bin/awk -v var="${1}" '{print $var}';
return 0
};
[[ "${1}" =~ ^nr[0-9]+$ ]] && {
/usr/bin/awk "NR==${1##+([a-z])}";
return 0
};
/usr/bin/awk "$@" && {
return 0
}
}
chomplastchar ()
{
chomp | python3 -c "import json,sys;print(sys.stdin.read()[:-1])"
}
pythonprint3 ()
{
python3 -c "print($1)"
}
chomp ()
{
perl -pe "chomp"
}