Este link pode ajudar Definir o consumo máximo de CPU em porcentagem por qualquer processo pesquisado por: MrSeed
este script pode ajudar também, qualquer um quer entrar sugestões sobre este script para melhorá-lo, será meu prazer
#!/bin/bash -xv
read -p "Which program u want to limit its processes?" ProgrameName
read -p "Which limitation percentage u want for it ?" limitationPercentage
read -p "Period to be sleep " sleepInterval
dataFile="/home/ahmedubuntu/Desktop/.file.txt"
separator="######"
trap "echo \"\" > $dataFile" SIGINT SIGTERM SIGHUP
########################################################
if [ -e $dataFile ]; then
echo "File $dataFile already exists!"
echo -e "" > $dataFile
else
echo >> $dataFile
fi
echo -e "$ProgrameName \n $limitationPercentage \n" >> $dataFile
getAllPIDRunUnderThisProgram=$( ps -e | grep "$ProgrameName" | awk '{print ;}')
echo -e "${getAllPIDRunUnderThisProgram[@]} \n $separator \n" >> $dataFile
for i in $getAllPIDRunUnderThisProgram
do
gnomeTab+=( --tab -e "cpulimit -p $i -l $limitationPercentage ")
done
gnome-terminal "${gnomeTab[@]}"
#echo gnome-terminal "${gnomeTab[@]}"
########################################################
while sleep $sleepInterval
do
i=0
while read line
do
if [ -n "$line" ] && ["$line" != "separator"]
then
programeNameAndPID[i]=$line
((i++))
elif [["$line" == "separator"]] ; then
getAllPIDRunUnderThisProgram=$( ps -e | grep "$programeNameAndPID[0]" | awk '{print ;}')
if [${#getAllPIDRunUnderThisProgram[*]} -gt ${#programeNameAndPID[*]}-2 ]
then
unset gnomeTab
newProcessNumber=${#getAllPIDRunUnderThisProgram[*]}-${#programeNameAndPID[*]}-2
index=${#getAllPIDRunUnderThisProgram[*]}-1
for (( c=$newProcessNumber ; c > 0 ; c-- ))
do
gnomeTab+=( --tab -e "cpulimit -p $getAllPIDRunUnderThisProgram[$index] -l $programeNameAndPID[1] ")
((index--))
done
gnome-terminal "${gnomeTab[@]}"
fi
i=0
unset programeNameAndPID
fi
done < $dataFile
done
e adicionando nice -10
funcionará bem sem necessidade de sudo e senha