why can user increase nice of process but decrease requires root?
Solution 1:
Yes. When every user in the system has the possibility to decreace the niceness of his process, then every user can cause other processes to starve.
Process priorities in the linux kernel do mean something. If you give a process the nice value of -20
it gets huge chunks of cpu time. That's why only root
can decrease those values.
Addition suggested by Eliah Kagan:
Why users cannot get their own processes back to the niceness level they themselves started them with?
The point is, the system doesn't note who did the increase of the niceness. So, there is no mechanism to find out whether you or root
did the incease.
Another approach is to say: a normal user shouldn't be able to overwrite the actions of a priviledged user. If root
is logged in and he wants to change the niceness of your processes to 20
: he can, and you should be prohibited to undo that changes. Untill the kernel doesn't remember who did the niceness changes, you will be prohibited.
Maybe some day the linux kernel developers include that functionality to the kernel code. You can do a feature request. But, be warned, kernel developers don't like new stuff just because it's cool.