
This will append the Top 10 most CPU hungry processes to a file ps.log every five seconds. So, additionally, run this (or use his answer for this part): while true do (echo "%CPU %MEM ARGS $(date)" & ps -e -o pcpu,pmem,args -sort=pcpu | cut -d" " -f1-5 | tail) > ps.log sleep 5 done You can then import this file into Gnumeric or the OpenOffice spreadsheet to create a nice graph (select 'separated by spaces' on import).Īs Scaine noticed, this won't be enough to diagnose the problem. This will log your cpu load every second and append it to a file uptime.log. You can add the -background or -b flag with the command to send the command to the background.This works very well: while true do uptime > uptime.log sleep 1 done If you stop the execution of cpulimit, the CPU usage of that specific process will go back to normal.Ī great solution to prevent this issue is to run cpulimit in the background. Here, cpulimit will restrict the CPU usage of the process as long as it's running. To force a process with PID 81550 to use only 50% of the CPU: sudo cpulimit -p 81550 - limit 50 You can use the -limit or -l flag of the cpulimit utility to add a limit to the resources that a process can use. The basic syntax of the command is: cpulimit -p pidĬpulimit -P /path-to-executable Limit the CPU Usage of a Process -P or -path: Absolute path of the executable file.-e or -exe: The name of the executable file.-p or -pid: The process ID of a process.To use cpulimit, you'll have to pass one of the following three arguments with the command: Therefore, to install it on CentOS and RHEL distributions, you'll have to enable the EPEL repository first. On Arch-based distributions like Manjaro Linux: sudo pacman -S cpulimitĬpulimit is available on the EPEL (Extra Packages for Enterprise Linux) repository. You can install the package on Ubuntu and other Debian-based distributions as follows: sudo apt install cpulimit
