简体   繁体   English

为什么`sched_setscheduler()`需要root priveledges?

[英]Why does `sched_setscheduler()` require root priveledges?

Why does sched_setscheduler() require root priveledges? 为什么sched_setscheduler()需要root priveledges?

I am writing some code that benefits from setting SCHED_FIFO. 我正在编写一些可以从设置SCHED_FIFO中受益的代码。 But if I use sched_setscheduler() I now must require this process to be run as root. 但是,如果我使用sched_setscheduler(),我现在必须要求以root身份运行此过程。 Why not allow sched_setscheduler() to be run without root permissions? 为什么不允许在没有root权限的情况下运行sched_setscheduler()

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. 可能是因为使用实时调度程序的进程可以完全接管计算机而不会将CPU提供给其他进程 - 普通用户不应该有权执行此操作。

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: Linux允许您比以root身份运行更细粒度的控制,但您可以使用以下命令在可执行文件上设置CAP_SYS_NICE 功能 (以root用户身份完成一次):

 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. 这将允许您的可执行文件使用sched_setscheduler,即使它不是以root用户身份运行。

因为它允许您的进程更改其他进程获得的CPU数量,这可能会被滥用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM