A process can cause the computer to "freeze" for example when exhausting CPU or swap. Is there a way to prevent this from happening? For example by setting the max %CPU or IO MB/s that can be granted to a process?
For a command you run from the shell, read the shell documentation on
There is a
ulimit() function that does the same thing in C.
There are also various limits you can apply via implementation-specific methods. In FreeBSD, you can set limits per user in
login.conf, or using a command called
rctl. Some Linux distros use a
There is a program called
cpulimit that pauses a process to make sure it uses less than a certain amount of the CPU over time.
And of course, there's always
renice, if you just want to tweak priorities.
ulimit which is usually a shell helper command. (In bash,
help ulimit). You can limit its memory, total CPU cycles and time (but not a percentage), and size of files written by it.
You can also use the
nice command. But in reality, if there is nothing else demanding resources, nice won't have an effect. It only comes into effect when multiple processes are contending for CPU resources.
On Linux, one thing you can do is tell the OOM killer that this process should be killed first when memory is low.