Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a way to stop ClamScan eating my server CPU?

share|improve this question

4 Answers 4

up vote 12 down vote accepted

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 20

  • By its PID:

    1. Find the PID of the process: pidof foo. (say, it outputs 1881)
    2. sudo cpulimit -p 1881 -l 20
share|improve this answer
    
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
    
sudo is not required the process isn't a system process. Just as a note –  Anwar Shah Oct 15 '12 at 3:56

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.

share|improve this answer
    
It looks like it still works eating a lot of cpu... –  Pitto Jan 11 '11 at 14:41
4  
As 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  
+1. niceing is the traditional way to go, and for good reason. –  loevborg Jan 11 '11 at 16:13

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.