tracker-miner-f, tracker-store, tracker-extract and dropbox processes are killing my CPU, they make it run at over 100%, overheating my laptop.
I have installed CPULIMIT and it works great restricting these processes, however, I cannot get it to autostart.
I have followed this but it does not work, the daemon starts but I think there is an error in the creation of the script and it does not actually limit any processes.
Is there a way to reduce cpu usage without having to manually do it through terminal every time I start a new session?
Ubuntu 14.04
A script I have found below, only partly runs and does not detect the PID correctly.
If someone has better knowledge than me, could you check the line:
NEW_PIDS_COMMAND="top -b -n1 -c | grep -E '$BLACK_PROCESSES_LIST' | gawk '\$9>CPU_LIMIT {print \$1}' CPU_LIMIT=$CPU_LIMIT"
Is this correct?
#!/bin/bash
# ==============================================================
# CPU limit daemon - set PID's max. percentage CPU consumptions
# ==============================================================
# Variables
CPU_LIMIT=40 # Maximum percentage CPU consumption by each PID
DAEMON_INTERVAL=3 # Daemon check interval in seconds
BLACK_PROCESSES_LIST="dropbox" # Limit only processes defined in this variable. If variable is empty (default) all violating processes are limited.
WHITE_PROCESSES_LIST= # Limit all processes except processes defined in this variable. If variable is empty (default) all violating processes are limited.
#PID Variables
NEW_PIDS_COMMAND=
NEW_PIDS=
LIMITED_PIDS=
QUEUE_PIDS=
# Check if both of the variables BLACK_PROCESSES_LIST or WHITE_PROCESSES_LIST are defined.
if [[ -n "$BLACK_PROCESSES_LIST" && -n "$WHITE_PROCESSES_LIST" ]]
then
# If both variables are defined then error is produced.
echo "At least one or both of the variables BLACK_PROCESSES_LIST or WHITE_PROCESSES_LIST must be empty."
exit 1
# If Black_Processes_List is defined
elif [[ -n "$BLACK_PROCESSES_LIST" ]]
then
# Set NEW_PIDS_COMMAND variable to below command
NEW_PIDS_COMMAND="top -b -n1 -c | grep -E '$BLACK_PROCESSES_LIST' | gawk '\$9>CPU_LIMIT {print \$1}' CPU_LIMIT=$CPU_LIMIT"
# If White_Processes_List is defined
elif [[ -n "$WHITE_PROCESSES_LIST" ]]
then
# Set NEW_PIDS_COMMAND variable to below command
NEW_PIDS_COMMAND="top -b -n1 -c | gawk 'NR>6' | grep -E -v '$WHITE_PROCESSES_LIST' | gawk '\$9>CPU_LIMIT {print \$1}' CPU_LIMIT=$CPU_LIMIT"
else
NEW_PIDS_COMMAND="top -b -n1 -c | gawk 'NR>6 && \$9>CPU_LIMIT {print \$1}' CPU_LIMIT=$CPU_LIMIT"
fi
# Search and limit violating PIDs
while sleep $DAEMON_INTERVAL
do
NEW_PIDS=$(eval "$NEW_PIDS_COMMAND") # Violating PIDs
LIMITED_PIDS=$(ps -eo args | gawk '$1=="cpulimit" {print $3}') # 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 -z & # Limit new violating processes
done
done
I only want to black list specific applications so I have altered to this:
#!/bin/bash
# CPU limit of a process
#
# Variables
CPU_LIMIT=50 # Maximum percentage CPU consumption by each PID
# 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.
DAEMON_INTERVAL=3 # Daemon check interval in seconds
PROCESS_1="" # Processes to be limited. If variable is empty (default) all violating processes are limited.
if [ -n "$PROCESS_1" ] # Process_1 entered
then
PID_1="pidof $PROCESS_1" # Set NEW_PIDS_COMMAND variable to below command
echo "Limit Process of: $PROCESS_1"
cpulimit --pid "$PID_1" -b -l "$CPU_LIMIT" # Run cpulimit with selected paramters
else
echo "All Processes limited to: $CPU_LIMIT"
PID_1="top -b -n1 -c | gawk 'NR>6 && \$9>CPU_LIMIT {print \$1}' CPU_LIMIT=$CPU_LIMIT" # Set global CPU limit
fi
# Search and limit violating PIDs
while sleep $DAEMON_INTERVAL
do
NEW_PIDS=$(eval "$PID_1") # Violating PIDs
LIMITED_PIDS=$(ps -eo args | gawk '$1=="cpulimit" {print $3}') # 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 -z & # Limit new violating processes
done
done
This works, but how do I limit multiple processes? At the moment it is either one or all ... Thanks
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
.dropbox
process running and taking up >40% CPU on your system? Please edit your question and include the output ofps -aux | grep dropbox
showing the offending process.