Is there a way to stop ClamScan eating my server CPU?
5 Answers
Install cpulimit
sudo apt-get install cpulimit
It provides different methods of limiting the CPU usage of a process foo to say, 20%
By its process-name:
sudo cpulimit -e foo -l 20.By its absolute path name:
sudo cpulimit -P /usr/bin/foo -l 20By its PID:
- Find the PID of the process:
pidof foo. (say, it outputs 1881) sudo cpulimit -p 1881 -l 20
- Find the PID of the process:
-
No target process found... Maybe it's because I have a script to run clamscan? i do: sudo cpulimit -e /etc/cron.hourly/virusscan -l 15 – Pitto Jan 11 '11 at 14:22
-
@Pitto: You have entered a wrong command, `/etc/cron.hourly/virusscan` is not a process. If you need to limit `clamscan`, run `sudo cpulimit -e clamscan -l 15`. – Sid Jan 11 '11 at 14:32
-
Oh! Right! So I should start cpulimit at startup in rc.local, right? – Pitto Jan 11 '11 at 14:51
-
2`sudo` is not required the process isn't a system process. Just as a note – Anwar Oct 15 '12 at 03:56
-
This would be a really neat solution if used programattically! Does it support pattern-based searches? – Jonny Asmar Dec 29 '17 at 19:42
Just as an alternative to cpulimit:
You could start clamscan with the nice-command, e.g.
nice -n 19 clamscan.
See man nice for details.
It does NOT limit the CPU, but it does lower the priority of the process.
Also there is renice to alter the priority of running processes.
- 4,937
- 2
- 16
- 19
-
3
-
5As long as no other process requires cputime, clamscan gets a lot of it. But as soon as another process (which has a higher priority) needs cputime, clamscan has no chance. cpulimit limits absolute cputime, and nice limits relative cputime. – Clausi Jan 11 '11 at 16:06
-
2
-
Are there any tools to define a default nice value for particular applications to run with? Preferably a tool that lets you compare all of your presets side-by-side. – Jonny Asmar Dec 29 '17 at 19:40
This was going to be a comment on Clausi's answer (which I believe is the most "correct" from a system administration viewpoint, in my opinion) but it bloomed into something too big to fit in the comment box.
Clamscan has a fixed amount of work to do so limiting it to a certain speed means it's just going to take longer. It's going to hold the CPU in contention for longer.
Allow it to run as fast as it can means you use your CPU to its fullest. Making it very "nice" means it'll let other processes do their work before its own. This means if there are lots of other busy processes, yes, it'll take a long time to do its own work but if there's nothing on there, it'll just chunk through its workload.
- 289,791
- 117
- 680
- 835
This topic can be useful: HOWTO: Set maximum CPU consumption in percentage by any process
- 2,346
- 2
- 23
- 28