How can I limit CPU usage on my Linode?

Linode Staff

I have a process that's using a lot of CPU, and would like to limit that. How can I do it?

1 Reply

You can manually limit CPU usage of a process with cpulimit:

# For Debian/Ubuntu-based systems:
apt-get install cpulimit

# For Redhat-based systems:
yum install epel-release
yum install cpulimit

# Limit usage of a process to 80% based on PID, executable filename, or
# absolute path:
cpulimit --pid=$PID --limit=80
cpulimit --exe=$EXECTUABLE_FILENAME --limit=80
cpulimit --path=/path/to/process_to_limit

If limiting a process using its PID, you can find that using top or ps:

# Using top:
top

# Using ps 
# Either of these commands is valid. The second command will capture
# the PID you're looking for in a variable called `$PID`
ps aux | grep $PROCESSNAME | head -n1
PID=$(ps aux | awk '/$PROCESS_NAME/{print $2}' | head -n1)

This article from TecMint gives a bit more information about cpulimit and how to use it.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct