Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does `sched_setscheduler()` require root priveledges?

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?

like image 649
Trevor Boyd Smith Avatar asked Jan 10 '23 04:01

Trevor Boyd Smith


2 Answers

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.

like image 69
nos Avatar answered Jan 17 '23 17:01

nos


Because it allows your process to change how much CPU other processes get, which can be abused.

like image 25
unwind Avatar answered Jan 17 '23 19:01

unwind