Rename the header using ps
' -o field=name
syntax with an empty name
:
cpu_percent=$(ps -p "$yourpid" -o %cpu=)
To test whether it's greater than some value, we can strip the decimals (bash can't handle them) and compare:
yourpid=$$ # Example using current shell's pid
cpu_percent=$(ps -p "$yourpid" -o %cpu=)
echo "Fractional percent is $cpu_percent"
cpu_percent=${cpu_percent%%.*}
echo "Integer percent is $cpu_percent"
if [ "$cpu_percent" -ge 40 ]
then
echo "It's more than 40"
fi