我正在尝试编译“slock”以实现一些调整。它无法启动,在此:
#ifdef __linux__
#include <fcntl.h>
static void
dontkillme(void) {
int fd;
fd = open("/proc/self/oom_score_adj", O_WRONLY);
if (fd < 0 && errno == ENOENT)
return;
if (fd < 0 || write(fd, "-1000\n", 6) != 6 || close(fd) != 0)
die("cannot disable the out-of-memory killer for this process\n");
}
#endif
我继续进行调试,发现我从 write()
获得了 EACCESS。
有什么收获?我相信这是一些安全功能,因为如果流程可以更改此值,这并不酷——但我做错了什么?二进制文件上是否有一些特殊的文件系统标志要设置,才能完成这项工作?
最佳答案
查看内核中的Documentation/filesystems/proc.txt
:
The value of /proc/pid/oom_score_adj may be reduced no lower than the last value set by a CAP_SYS_RESOURCE process. To reduce the value any lower requires CAP_SYS_RESOURCE.
这意味着您必须是 root 用户或在某个时候具有 CAP_SYS_RESOURCE 能力才能将其设置为低于默认值。
关于linux - EACCESS写/proc/self/oom_score_adj,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26963700/