Foi o que fiz para resolver o meu problema:
sudo apt-get install cpulimit ; sudo apt-get install gawk ; sudo apt-get install top
Então eu alterei um script para se adequar:
#!/bin/bash
# CPU limit of a process
#
# Variables
# NOTE: If your machine has one processor you can limit the percentage from 0% to 100%, which means that if you set for example 50%, your process cannot use more than 500 ms of cpu time for each second. But if your machine has four processors, percentage may vary from 0% to 400%, so setting the limit to 200% means to use no more than half of the available power.
CPU_LIMIT_1=50 # Maximum percentage CPU consumption by PROCESS_1
CPU_LIMIT_2=55 # Maximum percentage CPU consumption by PROCESS_2
CPU_LIMIT_3=60 # Maximum percentage CPU consumption by PROCESS_3
CPU_LIMIT_4=40 # Maximum percentage CPU consumption by PROCESS_4
PROCESS_1="dropbox" # Process 1 to be limited. If variable 1 is empty (default) all violating processes are limited.
PROCESS_2="tracker-miner-f" # Process 2 to be limited
PROCESS_3="tracker-store" # Process 3 to be limited
PROCESS_4="tracker-extract" # Process 4 to be limited
PROCESS_5="chrome" # Process 5 to be limited
gnome-terminal -x top
if [ -n "$PROCESS_1" ] || [ -n "$PROCESS_2" ] || [ -n "$PROCESS_3" ] || [ -n "$PROCESS_4" ] || [ -n "$PROCESS_5" ] ; then
while true;
do
echo "Limit the Process of: $PROCESS_1 to $CPU_LIMIT_1"
cpulimit --exe "$PROCESS_1" -b -l "$CPU_LIMIT_1"
sleep 3
echo "Limit the Process of: $PROCESS_2 to $CPU_LIMIT_1"
cpulimit --exe "$PROCESS_2" -b -l "$CPU_LIMIT_1"
sleep 3
echo "Limit the Process of: $PROCESS_3 to $CPU_LIMIT_1"
cpulimit --exe "$PROCESS_3" -b -l "$CPU_LIMIT_1"
sleep 3
echo "Limit the Process of: $PROCESS_4 to $CPU_LIMIT_1"
cpulimit --exe "$PROCESS_4" -b -l "$CPU_LIMIT_1"
sleep 3
echo "Limit the Process of: $PROCESS_5 to $CPU_LIMIT_3"
cpulimit --exe "$PROCESS_5" -b -l "$CPU_LIMIT_4"
sleep 60
done
else
echo "Process fields empty"
fi
exit 1
Criei uma pasta no meu menu inicial chamada start e movi o script para lá.
Eu quero executá-lo quando eu queria, então eu criei um lançador usando 'menulibre' com a opção de executar no terminal.
Pode haver uma maneira melhor, mas por enquanto isso funciona ... qualquer solução melhor será bem-vinda!
Obrigado
Além disso, isso restringe um processo individual ou global:
#!/bin/bash
# CPU limit of a process of one application or set global limit
#
#
DAEMON_INTERVAL=3 # Daemon check interval in seconds
gnome-terminal -x top
read -p "Do you want to set global CPU limitations y or n : " y
if test "$y" = "y" ; then
read -p "Enter Global CPU limit :" CPU_LIMIT_ALL
echo $'\nAll Processes shall be limited to:' $CPU_LIMIT_ALL
while true
do
PID_1="top -b -n1 -c | awk 'NR>6 && $9>CPU_LIMIT_ALL {print $1}' CPU_LIMIT_ALL=$CPU_LIMIT_ALL" # Set global CPU limit reads TOP list
NEW_PIDS=$(eval "$PID_1") # Violating PIDs
LIMITED_PIDS=$(ps -eo args | gawk '=="cpulimit" {print }')
# Already limited PIDs
QUEUE_PIDS=$(comm -23 <(echo "$NEW_PIDS" | sort -u) <(echo "$LIMITED_PIDS" | sort -u) | grep -v '^$') # PIDs in queue
for i in $QUEUE_PIDS
do
cpulimit -p "$i" -l "$CPU_LIMIT_ALL" -z & # Limit new violating processe
done
done
elif test "$y" = "n" ; then
read -p "Enter process to be restricted or press enter :" r
read -p "Enter value of CPU limit or press enter :" l
while true
do
echo $'\nProcess Entry Found'
echo $'CPU Entry Found\n'
echo "Limit the Process of: $r to $l"
cpulimit --exe "$r" -b -l "$l" -z & # Set CPU limit for process
sleep 60
done
else
echo "No input found"
exit 1
fi
Salve como .sh e torne executável e execute o tutorial
Se precisar, você também pode executar os scripts como root para restringir todos os processos do sistema também.
sudo / caminho / para / script /