Linux - Limit a process from consuming cpu resource, How to limit cpu usage of a process
Limit a process from consuming cpu resourceAt time we might feel to limit a process which is consuming too much of CPU memory or CPU resources. I am sure all the developers will be interested to limit the CPU resources consumed by their programs or code. I am not sure whether it can be done windows or not but it can be done in linux. How do I limit or force a process to consume only 20% of cpu resource?
# cpulimit -p pid -l 20
This can be achieved by using cpulimit program or binary. Limits are expressed in percentage and not in cpu time. cpulimit does not act on the nice value or other scheduling priority stuff, but on the real cpu usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly.
# cd /tmp # wget 'http://downloads.sourceforge.net/cpulimit/cpulimit-1.1.tar.gz' # tar -zxvf cpulimit-1.1.tar.gz # cd cpulimit-1.1 # make # cp cpulimit /usr/local/sbin/ # rm -rf cpulimit*
For Debian Linux
# sudo apt-get update # sudo apt-get install cpulimit
How to use cpulimit?
Limit a process by using process name. Limit a process called firefox to 20 percent.
# cpulimit -e firefox -l 20
TO Limit a process using process id or PID.
# cpulimit -p 4649 -l 20 Process 4649 detected
Limit a process called firefox bu using absolute path name of the executable:
# cpulimit -P /usr/lib/firefox-3.6/firefox -l 20
-p : Process PID.
-e : Process name.
-l : percentage of CPU allowed from 0 to 100.
-P: absolute path name of the executable program file.
How to find the process ID or PID of a process
# ps aux | less # ps aux | grep firefox # ps -o comm,pid -u math | grep firefox firefox 4659
The topic on Linux - Limit a process from consuming cpu resource is posted by - Math
Hope you have enjoyed, Linux - Limit a process from consuming cpu resourceThanks for your time