On Mon, Jan 14, 2008 at 01:34:13PM +0000, Andreas Kahari wrote: > On 14/01/2008, Alexander Schrijver <[EMAIL PROTECTED]> wrote: > > On Jan 14, 2008 1:30 PM, Andreas Kahari <[EMAIL PROTECTED]> wrote: > > > On 14/01/2008, Alexander Schrijver <[EMAIL PROTECTED]> wrote: > > > > On Jan 14, 2008 11:52 AM, Andreas Kahari <[EMAIL PROTECTED]> wrote: > > > > > > > > > > Is there a way of limiting the amount of CPU given to a particular > > > > > process or process group? For example, I would want the build of the > > > > > qt4 port to use a maximum of 25% of the available CPU, leaving the CPU > > > > > 75% idle if nothing else is happening on the machine. > > > > > > > > > > I know about 'nice', but it doesn't fulfil the criteria that the > > > > > machine is left otherwise idle if nothing else runs on it. > > > > > > > > > > I don't have a real reason for why I would want to do this, I'm mainly > > > > > curious as to if it's possible. > > > [cut] > > > > > > > > I have never done this myself, but I believe this is possible by > > > > creating a login class in /etc/login.conf and set the cputime option. > > > > See login.conf(5) for a better description.
> > > > > > I believe that the cputime resource limit will limit the maximum > > > amount of CPU time that the user may use in a session, which is not > > > really what I asked for. I'd like the process or process group to run > > > for as long as it needs to run, but that it only ever uses a fraction > > > of the CPU power. > > > > > > It's like limiting the network bandwidth for a particular type of > > > traffic, only this is about time on the CPU. > > > > > As I said, I don't have a good reason for wanting to do this. It just > seemed like something someone might want to do. But let me dream up > three examples: Sometimes firefox (or whatever program) goes a bit > haywire and brings the machine to a crawl. It would be nice to limit > firefox's CPU to a maximum of, say, 50% so that I'm guaranteed to have > 50% of the machine to work with. Well, if firefox is set to be quite nice, then your normal user session should end up with a higher priority and you shouldn't notice that firefox has gone haywire. In this instance, you really don't have a need to keep the CPU from being at 0% idle but rather want to maintain responsiveness with other processes. This is what nice is for. > > Another example: Let's say I'm rebuilding the kernel, base system, and > all my packages after a major update from CVS after a long time away. > I'm not worried about how long this takes so I'm quite happy to run > the build at 5% of the CPU while I get on with my work. > As above. > Third example, similar to the last one: I'm running a distributed.net > or SETI-at-home client in the background, but I don't ever want it to > run at 100% of the CPU, maybe because that would make the machine too > noisy during the night (due to the fans). > What you want to do here is throttle the CPU down. > Maybe no-one has these kind of requirements? On my machines, if something is going haywire its more likely that its I/O bound and regular nice doesn't help. If I want a process to plod along, I'll farm it out to a slower box, eg a P-II instead of the Athlon64. So perhaps this is your answer. Get a slow quiet box for your SETI-at-home or whatever for over night and use your main box during the day. Doug.

