Oh but cgroups are easy :) Install the libcgroup package. Create a /etc/cgconfig.conf:
mount {
cpu = /cgroup/cpu_and_mem;
cpuacct = /cgroup/cpu_and_mem;
memory = /cgroup/cpu_and_mem;
}
group sshd {
cpu {
cpu.shares="500";
}
cpuacct {
cpuacct.usage="0";
}
memory {
memory.limit_in_bytes="1G";
}
}
group nosshd {
cpu {
cpu.shares="500";
}
cpuacct {
cpuacct.usage="0";
}
memory {
memory.limit_in_bytes="1G";
}
}
Start the cgconfig
process which will create the hierarchy, cgroups, and set the limits. If that succeeds, you have two cgroups, both of which have 50% of the CPU assigned and 1G of memory available (don't know what your actual amount of available memory is; assuming it's 2G in this example). Now you just need to move all the tasks (ie all processes running on the system) from the root group into the nosshd cgroup:
cgroup]# cat tasks >> nosshd/tasks
cgroup]# echo > tasks
Then you just need to get the PID of the sshd
process and move it info the sshd tasks file:
cgroup]# echo $PID >> sshd/tasks
Ta-da, you're done. You can now rest assured that sshd will always have 50% of the CPU and 1G of memory.
sshd
is well behaved, I think it would stuck if there is not enough CPU/RAM to use, wouldn't it?