pthread_setschedparam 返回 EPERM 异常

在工作中遇到使用 pthread_setschedparam时,返回了EPERM 异常,该异常是说没有权限。
程序运行的环境是,ssh 连接到一台linux环境下,sudo su切换到root用户。这似乎是一个系统bug。详细的过程见:https://github.com/coreos/bugs/issues/410

从该issue中,提供了两种方法:

第一:更改 kernel.sched_rt_runtime_us 值为 -1.
操作:sysctl kernel.sched_rt_runtime_us,先查看当前值
在我的环境下,kernel.sched_rt_runtime_us = 950000
sysctl -w kernel.sched_rt_runtime_us=-1 更改这个配置项。
然后再重新运行你的程序。本人使用此方法有避免EPERM异常

第二:把当前ssh连接进来的shell,添加进 cpu:/ 组下,以保证有权限操作。
原文解释说,systemd默认情况下,把ssh连接添加在一个非RT组下,此时当你需要通过ssh连接的前台,运行FIFO/RR 任务时,并不能正常执行。
操作是:cgclassify -g cpu:/ $$
也添加在service文件的[Service]项下,添加 ControlGroup=cpu:/

   原文如下:
   what may or may not be very related, systemd defaults put ssh connections into a non-RT cgroup. if you're trying to ssh in and run FIFO/RR tasks, it just won't work. you need to move your shell into the default cpu:/ group which does permit priority scheduling.cgclassify -g cpu:/ $$your systemd unit file can start your service and get priority scheduling if you put ControlGroup=cpu:/ under [Service]

第二种方法,本人没有亲试过,请谨慎选择。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值