Limit your Linux's CPU Process
I found cpulimit is pretty useful for the scripts running from cron, for example I can do overnight backups and be sure that compression of 50GB file via rar won’t ate all CPU resources and all other system processes will have enough CPU time.
In most of Linux distributions cpulimit is available from binary repositories so you can install it using commands:
or
If it’s not possible in your distro then it’s extremely easy to compile it:
From that moment you can run commands limited by CPU percentage, e.g. below command executes gzip compression so that gzip process will never step over 10% of CPU limit:
You can check actual CPU usage by gzip using commands:
or
Btw, the first command contains ‘grep [g]zip’ to avoid the last line in common output:
Using cpulimit you can also allocate CPU limit to already running processes, e.g. below command will allocate 20% CPU limit to process with PID 2342:
It’s possible to specify process by its executable file instead of PID: