为什么`sched_setscheduler()`需要root特权? [英] Why does `sched_setscheduler()` require root priveledges?
问题描述
为什么sched_setscheduler()
需要根特权?
我正在编写一些受益于设置SCHED_FIFO的代码.但是,如果我使用sched_setscheduler(),则现在必须要求该进程以root用户身份运行.为什么不允许sched_setscheduler()
在没有root权限的情况下运行?
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?
推荐答案
大概是因为使用实时调度程序的进程可以完全接管一台计算机,而不会将CPU交给其他进程-普通用户不应该这样做.
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允许您比以root身份运行更精细的控制,但是您可以将CAP_SYS_NICE设置为
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
即使未以root用户身份运行,这也将允许您的可执行文件使用sched_setscheduler.
Which will allow your executable to use sched_setscheduler even when it's not run as the root user.
这篇关于为什么`sched_setscheduler()`需要root特权?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!