I want to limit the percentage of CPU a user who ssh to my comp can use like say only 25% cpu usage at max. How do i do this in ubuntu ?
Ubuntu – Limit CPU usage for a user in Ubuntu
cpu usageUbuntu
Related Solutions
I install NoScript on every system with Firefox, which blocks Flash along with Java and Javascript until I allow it from particular sites. This cuts down on sites loading flash widgets for something ridiculous like their site banner, or advertisements that are sneaky and hiding.
It also has the added benefit of security. Yes, its a pain to whitelist sites you trust, and you really must be careful of what you're going to allow; whitelisting everything defeats the purpose of the plugin. Security and convenience are mutually exclusive, anyway.
The processor usage percent is calculated with "the amount of time that the processor is not on idle". I mean, this calc is made from a counter that register the usage of the "idle" running process. While another preocesses "rob" the processor power from the idle process, the idle processor consumer register is decreased by a factor; as the time line is fixed and constant, the (1-"%time in the idle taks") is the amount of processor load used for all processes running on a processor:
Defining CPU utilization
For our purposes, I define CPU utilization, U, as the amount of time not in the idle task, as shown in Equation 1.
The idle task is the task with the absolute lowest priority in a multitasking system. This task is also sometimes called the background task or background loop, shown in Listing 1. This logic traditionally has a while(1) type of loop. In other words, an infinite loop spins the CPU waiting for an indication that critical work needs to be done.
Listing 1: Simple example of a background loop
int main( void )
{
SetupInterrupts();
InitializeModules();
EnableInterrupts();
while(1) /* endless loop - spin in the background */
{
CheckCRC();
MonitorStack();
... do other non-time critical logic here.
}
}
This depiction is actually an oversimplification, as some "real" work is often done in the background task. However, the logic coded for execution during the idle task must have no hard real-time requirements because there's no guarantee when this logic will complete. In fact, one technique you can use in an overloaded system is to move some of the logic with less strict timing requirements out of the hard real-time tasks and into the idle task.
Best Answer
I think you can't do that. What you can do is modifying priority for user. You can do that by editing file
/etc/security/limits.conf
:Sets priority for john's processes to 20 (effective after next login). 20 is lowest priority.
This way john can use 100% of CPU, but if someone else needs it, other user will immediately get it, and john's tasks will wait (or actually slow down, not stop completely).