Limit CPU utilisation/core

I was wondering if I it is possible to limit the CPU utilisation of a flatpak application, or restrict it to fewer number of CPU cores? I keep getting these random periods of high CPU utilisation for no reason for some applications like MS Teams, and Zoom. If I could limit them to a core (I am on a quad-core Ryzen), maybe then my desktop wouldn’t freeze due to these buggy applications.

Thoughts?

1 Like

Someone proposed an article for Fedora Magazine about the cpulimit utility a while back but never followed through: Using cpulimit to control CPU intensive processes

I haven’t used it, but it sounds like it is what you are looking for. You could probably add it to the Exec line of your launchers. So, for the example programs you mention, something like the following might work (untested):

Limit MS Teams to 50% CPU:

$ sudo dnf install -y cpulimit
$ cp /usr/share/applications/teams.desktop ~/.local/share/applications
$ sed -i 's/teams %U/cpulimit -i -l 50 teams %U/' ~/.local/share/applications/teams.desktop
$ update-desktop-database ~/.local/share/applications

Limit Zoom to 50% CPU:

$ sudo dnf install -y cpulimit
$ cp /usr/share/applications/Zoom.desktop ~/.local/share/applications
$ sed -i 's!/usr/bin/zoom %U!/usr/bin/cpulimit -i -l 50 /usr/bin/zoom %U!' ~/.local/share/applications/Zoom.desktop
$ update-desktop-database ~/.local/share/applications
5 Likes

Interesting, since I use both Teams and Zoom as flatpak, I can’t really change the Exec command. But I think I can write a small script to “limit by PID” when the resource utilisation starts spiking. Something like:

cpulimit -il 200 -v -p $(pgrep -f 'bwrap --args [0-9]+ <app>' | head -1)

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.