Question regarding cpulimit

Hi all, :wave:

I´ve got a question about the correct usage of cpulimit ( ).

With the help of CPU Usage Limiter for Linux you can limit the maximum percentage of CPU time that a process is allowed to consume.

I also found a pretty good description here: cpulimit › Wiki › (although in German).

To make sure I understand it correctly:

Suppose a process or program called “foo” has started and is using 100% CPU.
With the following command the maximum CPU time can be limited to 50%:
cpulimit -e foo -l 50 # -e: name of the process

[… or:]

The following command can be used to limit the maximum CPU time consumed by the process with PID “1234” to 20%:
cpulimit -p 1234 -l 20 # -p: PID of the process

(translated from German; source: cpulimit › Wiki › )

But let´s say the process “foo” (process ID: 1234) takes up 30% of the RAM (without invoking cpulimit) and I´ll try to limit it thus:

cpulimit -p 1234 -l 50

Then it should have no effect, right :question:
The 50% limitation refers to 100% of the CPU time to be used, and the 30% usage is already below 50%.

Hopefully I got right. :thinking:

If I wanted to make the process use 50% of what it´s using right now (30%) my command should be:

cpulimit -p 1234 -l 15

Can anyone confirm I understood it correctly :question:

Many thanks in advance …
… and many greetings

Rosika :slightly_smiling_face:

Aren’t you mixing up RAM (memory) usage with CPU usage?

So, it’s like this: if process foo is using 30% of one CPU, and you want to cut this number in half, you

issue: cpulimit -e foo -l 15

Usually you wouldn’t use a number so low. Keep in mind that, if you have a computer with, say 4, CPUs and your program is doing some heavy number crunching, then you would use e.g. cpulimit -e foo -l 200, thus assigning the computing powers of two cores to foo and leaving you with the other too.

RAM usage doesn’t come into play here. It also doesn’t seem to make any sense to me to limit a program’s ability to access memory because in that case, excess data would be put into the swap space on disk, making the program extremely slow.

Now, to the concept itself. For me, putting a hard limit on CPU usage only makes sense, if you have a very long running program, and you don’t want your electricity bill to go too high.

If you just want to continue working whilst your program is running, it makes more sense to lower its priority with the nice and renice commands.

1 Like

Hi Mina, :wave:

be thanked a lot for your kind reply. :heart:

Uh, I hope not. I really want to deal with limiting CPU usage here. :blush:

Thanks. I guess that confirms what I was thinking.
I think it shouldn´t matter whether I use the “-e” parameter (name of the process) or the “-p” parameter (PID of the process).

Yes, you´re certainly right there. My example was just hypothetical.

I see.

Well, the background of my question is this:

I often help a friend of mine who lives pretty far away with her PC-related issues by connectiong to her laptop via anydesk.
This programme (anydesk) is not installed on my main PC but it´s rather running in my Debian virtual machine.

When I start anydesk on Debian CPU usage is still pretty low (in Debian as well as on my host).
But as soon as the remote connection is established and the remote desktop is “transmitted” to my system CPU usage goes up.

Alas I forgot to look up the exact values in Debian (VM) but noticed it on my host.

So I installed cpulimit on Debian and my intention was to limit the CPU usage of anydesk within the virtual machine.

Or do you think nice or renice would be better suited for my purposes :grey_question: :thinking:

Many thanks again.
Greetings from Rosika :slightly_smiling_face:

That depends: If you want to limit the overall CPU usage (for whatever reason), then cpulimit is the way to go. If you want to keep your other programs responsive on the possible expense of anydesk,

renice -n N -p P is the way to go. P is the process ID, N a number between -20 and 20, (e.g. 15). Lower number = higher priority.

1 Like

@Rosika ,
If you set a nice value for a shell, eg

nevj@trinity:~/common$ nice bash

then all commands you issue from that shell will inherit its niceness.
That could save a lot of nice commands


Very cool!

I didn’t know that.

1 Like

Hi again to all of you, :wave:

thanks a lot for your answers. :heart:


O.K., that sounds fine.

So if I understand it correctly now (hopefully), it should be like this:

I use cpulimit whenever I want to limit the CPU usage of a certain process under all circumstances - no matter what other (resource-hungry or not) processes are running at the same time.

Whereas when I use nice or renice CPU usage limitation may not even kick in IF no other resource-hungry processes are running at the same time :question: :question: :thinking:

I hope I got it right now…

Thanks so much. :slightly_smiling_face:


Hi Neville,

Wow, that´s really good to know. That may very well come in handy.

Thanks a lot for pointing that out.

Many greetings to all of you.
Rosika :slightly_smiling_face:


Basically yes. Only detail is, nice doesn’t put a limit. It just assigns places in the queue, if resources are limited. I think, this is what you want.

Have a lovely Sunday, BTW!


Thanks so much, Mina, for explaining the matter even further. :heart:

I see. Great. :+1:

Well, I think it´s best to try out both and see which works better…

The thing is:

When running Debian in a VM for using anydesk with my far-away friend the anydesk process is the only resource-hungry process running there. All other processes are lightweight compared to an active anydesk-session.

I think I´ll try out cpulimit and nice by installing the mathomatic-primes package as suggested here: Restricting process CPU usage using nice, cpulimit, and cgroups | Scout APM Blog .

The matho-primes command should generate high CPU usage (almost 100%)

Now run top and you will see that the matho-primes process is using all the available CPU.

…and this should set up the scenario for further cpulimit (…) testing. :smirk:

Thanks also for the good wishes, Mina. :heart:

Have a lovely and nice Sunday as well, of course. :smiling_face_with_three_hearts:

Many greetings and stay safe.
Rosika :slightly_smiling_face:

1 Like

Hi Mina, :wave:

so sorry to bother you again. :slightly_frowning_face:

Just wanted to let you know that (after installing the mathomatic-primes package on Debian) I tried it out.

cpulimit works just fine:
The command

cpulimit -l 50 matho-primes 0 9999999999 > /dev/null

produces a CPU usage of something between 52 % and 55 % (instead of 100 %) which is great. So it works as desired. :+1:

Yet nice doesn´t seem to work as it should:

… following the instructions on Restricting process CPU usage using nice, cpulimit, and cgroups | Scout APM Blog :

The commands

nice matho-primes 0 9999999999 > /dev/null &
matho-primes 0 9999999999 > /dev/null &

should start two processes of matho-primes , one with nice and one without.

The 1st command starts the process with a niceness of 10 (the default) but the two processes use the same amount uf CPU it seems (100 % vs 99.7 %).
And that´s despite the fact that a niceness of 10 is assigned to the first process. :thinking:
(see screenshot)

Well, I just wanted to let you know…

Many greetings from Rosika :slightly_smiling_face:

Hang on, I think I got it now.

I didn´t take into consideration the fact that even Debian has got 2 virtual cores assigned to the CPU in the VM.
Surely my observations must have something to do with that.

To (hopefully) prove it I started 3 processes of the kind I described above:

matho-primes 0 9999999999 > /dev/null &
matho-primes 0 9999999999 > /dev/null &
nice matho-primes 0 9999999999 > /dev/null

… and now the desired effect kicks in :smiley:


Two processes consuming 100 % and 90 % respectively but the third one just 9.7 %.

I guess that out of the three processes two are sharing the same core and then nice takes effect.
So it seems nice works as per core… :thinking: :question:

Hopefully I´ve got it right now …

Many greetings.
Rosika :slightly_smiling_face:


@Rosika and @Mina
Great discussion , thanks to both of you
We should note that both nice and cpulimit only affect cpu time usage.
They do not limit memory usage. That seems to be managed by ulimit.

1 Like

Hi Neville, :wave:

You´re welcome.
I have to point out that @Mina surely deserves most of the praise as she knows so much more than I do. :smiley:

Thanks a lot for the hint. :+1:

As a matter of fact I didn´t know about that one and was pretty much intrigued.
As there are no man-pages for that command on my system I found out:

type ulimit
ulimit is a shell builtin

Curiously enough I didn´t find any documentation about that in the wiki (which otherwise offers an abundance of information about any command [in German] , although there seem to be some discussions of ulimit in the respective forum). Perhaps I wasn´t looking thoroughly enough … :blush:

But I stumbled upon How to Use the ulimit Linux Command {With Examples}
from .
There seem to be be some good explanations and examples for the correct usage on that page.

Thanks so much for your input.
Many greetings from Rosika :slightly_smiling_face:


Hi @Rosika
Try man bash under COMMANDS and look for ulimit
Also man - k ulimit and man 3 ulimit
I dont really need to tell you. You have an ability to search around for answers.
I sometimes have to increase ulimit for programs that use a lot of ram for large matrix calculations.
I did not know about type so thank you for that.

It’s not that nice works per core. The thing is: The matho-primes program is probably a single threaded app, so it will never use more than one core.

With two cores and two instances, each one gets executed on one core. They are not competing for resources.

In the second example, with three instances on two cores, at least two instances have to share a single core. The one with the higher priority (lower nicevalue) has priority in grabbing CPU time.