{"id":37908,"date":"2022-03-15T16:49:03","date_gmt":"2022-03-15T16:49:03","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=37908"},"modified":"2022-03-15T16:49:03","modified_gmt":"2022-03-15T16:49:03","slug":"limit-cpu-usage-ubuntu","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2022\/03\/limit-cpu-usage-ubuntu\/","title":{"rendered":"How to Limit CPU Usage of Your Apps in Ubuntu 22.04 | 20.04"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo.webp\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" class=\"alignleft size-thumbnail wp-image-37909\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo-600x600.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/terminal-logo.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/a><\/p>\n<p>Want to limit the cpu usage of an app or process? It&#8217;s easy to do the trick in Ubuntu Linux via the <code>LimitCPU<\/code> tool.<\/p>\n<p>LimitCPU is a simple command line tool that monitors a process and makes sure its CPU usage stays at or below a given percentage, by sending SIGSTOP and SIGCONT POSIX signals to process. All the children processes and threads of the specified process will share the same percentage of CPU.<\/p>\n<p><a href=\"http:\/\/limitcpu.sourceforge.net\/\" rel=\"noopener\" target=\"_blank\">LimitCPU<\/a> is the direct child of the old <a href=\"http:\/\/cpulimit.sourceforge.net\/\" rel=\"noopener\" target=\"_blank\">CPUlimit<\/a>. It&#8217;s available in the system repositories of all current Ubuntu repositories, though the package name is cpulimit.<\/p>\n<h3>Install LimitCPU in Ubuntu:<\/h3>\n<p>Press <b>Ctrl+Alt+T<\/b> on keyboard to open terminal. When it opens, run command to install the tool:<\/p>\n<pre>sudo apt install cpulimit<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/apt-cpulimit.webp\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/apt-cpulimit-600x246.webp\" alt=\"\" width=\"600\" height=\"246\" class=\"alignnone size-large wp-image-37911\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/apt-cpulimit-600x246.webp 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/apt-cpulimit-300x123.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2022\/03\/apt-cpulimit.webp 728w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h3>How to use Limit CPU in Ubuntu:<\/h3>\n<p>It&#8217;s quite easy to use the tool, because it has a good documentation. Just run <b>man cpulimit<\/b> in terminal, it will tell you how to use it. For lazy men, here are some examples.<\/p>\n<p><b>1<\/b>. Specify app or process to limit via:<\/p>\n<ul>\n<li><b>-p<\/b> follow with process id<\/li>\n<li><b>-e<\/b> follow with executable file name.<\/li>\n<li><b>-P<\/b> follow with absolute path to executable file.<\/li>\n<\/ul>\n<p>For example, make sure process &#8216;1123&#8217; to use less than 50% CPU (<i>-l follow with number<\/i> specify allowed CPU). <\/p>\n<pre>cpulimit -p 1123 -l 50<\/pre>\n<p>Many apps now use multiple processes, so you may specify which to limit via path to executable:<\/p>\n<pre>cpulimit -P \/usr\/bin\/firefox -l 50<\/pre>\n<p><b>2.<\/b> The tool can also used to launch an app and limit its CPU usage. For example, launch Firefox and allow up to 50% CPU amount:<\/p>\n<pre>cpulimit -l 50 firefox<\/pre>\n<p><b>3.<\/b> There are some other command line flags, including:<\/p>\n<ul>\n<li><b>-c<\/b> specify the number of CPU cores available for the process.<\/li>\n<li><b>-b<\/b> \/ <b>-f<\/b> run cpulimit in background \/ foreground.<\/li>\n<li><b>-q<\/b> run in quite mode.<\/li>\n<li><b>-k<\/b>, kill the process when reach CPU limit.<\/li>\n<li><b>-s<\/b>, send alternative signal to watched process when kill it.<\/li>\n<\/ul>\n<p>For example, launch Firefox and kill it when reach 30% CPU usage:<\/p>\n<pre>cpulimit -l 30 -k firefox<\/pre>\n<p>Limit process &#8216;1123&#8217; to 25% CPU and allows 2 cores:<\/p>\n<pre>cpulimit -c 2 -p 1123 -l 25<\/pre>\n<p>Kill Firefox and send SIGTERM signal when it uses 20% CPU:<\/p>\n<pre>cpulimit -l 20 -e firefox -s SIGTERM<\/pre>\n<p>As mentioned, run <b>man cpulimit<\/b> in terminal for more information. <\/p>","protected":false},"excerpt":{"rendered":"<p>Want to limit the cpu usage of an app or process? It&#8217;s easy to do the trick in Ubuntu Linux via the LimitCPU tool. LimitCPU is a simple command line tool that monitors a process and makes sure its CPU usage stays at or below a given percentage, by sending SIGSTOP and SIGCONT POSIX signals [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":37909,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[2003],"class_list":["post-37908","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-cpupower"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/37908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=37908"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/37908\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/37909"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=37908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=37908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=37908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}