I have a bunch of processes of the same name - they take up 100% of my CPU time, I want this to be no more than 50%.
How can I do this without installing any extra software?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
For a kernel-level mechanism for this, you need to read up on Linux Control Groups. This is an area still in active development, so you'll need to ensure that what you read is consistent with the kernel you have (or are willing to install).
Although you said not to install anything additional, you might consider installing
cgred to automate moving processes with matching names to your CPU cgroup. On Debian, this in in the
You can do so with bash shell, sleep, pgrep, and pkill commands using STOP and CONT signals.
The following one-liner will make the processes use maximum of 50% of total availabile CPU time. It's going to run for each 100 miliseconds, then it'll be stopped for another 100 milliseconds.
while [ True ]; do pkill -STOP processname; sleep 0.1s; pkill -CONT processname; sleep 0.1s; done
Here's the same code split into multiple lines for readability:
while [ True ] do pkill -STOP processname sleep 0.1s pkill -CONT processname sleep 0.1s done
No mater how much processes exist maching the processname pattern, they can't excess 50% of CPU usage, becasue they are all stopped and continued at the same time - which means they need to share the avaiabile CPU time between them, when they are active. This ensures the limit is met.
There is a program called cpulimit that does roughly the same thing.
as written above could be used as a script to assist OOM-killer Or prevent its use as well
say when cpu overall hits 75% for x mins run pkill.sh
../scripts/boottime/OOMkiller.sh while [ true] ; do inxi -tcm5 > ~/cpu.log sleep 0.5s inxi -tcm5 >> ~/cpu/log | diff -m > ~/offender.log done for i in offender.log ; do ./scripts/pkill.sh done ../scripts/pkill.sh while [true] do pgrep $(i) -STOP $PID pkill -STOP $PID sleep 0.5s pkill -CONT $PID done