tracker-miner-f、tracker-store、tracker-extract、dropboxの各プロセスがCPUを殺しているため、100%以上で実行され、ラップトップが過熱しています。
CPULIMITをインストールしましたが、これらのプロセスを非常に制限して動作しますが、自動起動できません。
this に従いましたが、動作しません。デーモンは起動しますが、スクリプトの作成にエラーがあり、実際にプロセスを制限することはないと思います。
新しいセッションを開始するたびに端末で手動で行う必要なく、CPU使用量を減らす方法はありますか?
Ubuntu 14.04
以下で見つけたスクリプトは、部分的にしか実行されず、PIDを正しく検出しません。
誰かが私よりも優れた知識を持っている場合、次の行を確認してください:
NEW_PIDS_COMMAND="top -b -n1 -c | grep -E '$BLACK_PROCESSES_LIST' | gawk '\$9>CPU_LIMIT {print \$1}' CPU_LIMIT=$CPU_LIMIT"
これは正しいです?
#!/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
特定のアプリケーションのみをブラックリストに載せたいので、これに変更しました:
#!/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
これは機能しますが、複数のプロセスを制限するにはどうすればよいですか?現時点では、いずれかまたはすべてです...ありがとう
これは私の問題を解決するために私がやったことです:
Sudo apt-get install cpulimit ; Sudo apt-get install gawk ; Sudo apt-get install top
次に、スクリプトを次のように変更しました。
#!/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
ホームメニューにstartというフォルダーを作成し、そこにスクリプトを移動しました。
必要に応じて実行したいので、「menulibre」とターミナルで実行するオプションを使用してランチャーを作成しました。
より良い方法があるかもしれませんが、今のところこれは機能します...より良い解決策は歓迎します!
ありがとう
また、これは個々のプロセスまたはグローバルを制限するためのものです。
#!/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 '$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_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
.shとして保存してから実行可能ファイルを作成し、 tutorial を実行します
必要な場合は、rootとしてスクリプトを実行して、すべてのシステムプロセスも制限することもできます。
Sudo/path/to/script /
このスレッドは少し古いことを理解しています。ただし、指定された目標を達成するためのmuchより簡単な方法があります。希望するプロセスと制限を使用して、次のようなシェルスクリプトを簡単に作成できます。
#!/bin/bash
#Set this variable to the number of cores in your processor. This example is for an 8-core CPU. The reason that the number of cores is important is that you need to take it into consideration when setting cpulimit's -l option. This is explained on the cpulimit project page (see http://cpulimit.sourceforge.net/): "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."
NUM_CPU_CORES=8 #Change this number to reflect the number of cores in your processor.
cpulimit -e "dropbox" -l $((50 * $NUM_CPU_CORES))& #Limit "dropbox" process to 50% CPU usage.
cpulimit -e "tracker-miner-f" -l $((50 * $NUM_CPU_CORES))& #Limit "tracker-miner-f" process to 50% CPU usage.
cpulimit -e "tracker-store" -l $((50 * $NUM_CPU_CORES))& #Limit "tracker-store" process to 50% CPU usage.
cpulimit -e "tracker-extract" -l $((50 * $NUM_CPU_CORES))& #Limit "tracker-extract" process to 50% CPU usage.
cpulimit -e "chrome" -l $((40 * $NUM_CPU_CORES))& #Limit "chrome" process to 40% CPU usage.
上記のスクリプトを実行可能にし、他のスクリプトと同様に自動実行するように設定します(他のスクリプトを削除します)。実際には、cpulimitはバックグラウンドにとどまり、指定されたプロセスを監視し、プロセスが開始されるとすぐにcpulimitが制御を取り、指定された制限を有効にします。指定されたプロセスが終了するか強制終了されると、cpulimitが再びアクティブになるのを監視し、プロセスが繰り返されます。
起動時にプログラムを自動的に起動する場合は、起動アプリケーションに追加できます。詳細については、次の回答を参照してください。