Why does sched_setscheduler()
require root priveledges?
I am writing some code that benefits from setting SCHED_FIFO. But if I use sched_setscheduler() I now must require this process to be run as root. Why not allow sched_setscheduler()
to be run without root permissions?
Presumably because processes using a realtime scheduler can completely take over a machine and not give the CPU to other processes - which normal users should not have the power to do.
Linux allows you to do a bit more fine grained control than running as root though, you can set the CAP_SYS_NICE capability on your executable (done once, as the root user) with the command:
setcap cap_sys_nice+ep ./your_program
Which will allow your executable to use sched_setscheduler even when it's not run as the root user.
Because it allows your process to change how much CPU other processes get, which can be abused.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With