affinity - 检查 PF_NO_SETAFFINITY 的值

标签 affinity taskaffinity setthreadaffinitymask taskset

是否可以判断进程/线程是否设置了 PF_NO_SETAFFINITY 标志?我在一系列进程 ID 上运行任务集,其中一些进程抛出以下形式的错误:

任务集:无法设置 pid 30 的关联性:参数无效

我相信这是因为某些进程设置了 PF_NO_SETAFFINITY (请参阅 Answer )。

谢谢!

最佳答案

是的 - 查看 /proc/PID/stat 的“flag”字段

<linux/sched.h

#define PF_NO_SETAFFINITY 0x04000000        /* Userland is not allowed to meddle with cpus_allowed */

在此处查看有关使用/proc 的详细信息:

示例:

ps -eaf
www-data 30084 19962  0 07:09 ?        00:00:00 /usr/sbin/apache2 -k start
...

cat /proc/30084/stat
30084 (apache2) S 19962 19962 19962 0 -1 4194624 554 0 3 0 0 0 0 0 20 0 1 0 298837672 509616128 5510 18446744073709551615 1 1 0 0 0 0 0 16781312 201346799 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0

标志是4194624


Q: Do you mind specifying how you'd write a simple script that outputs true/false based on whether you're allowed to set affinity?

答:我觉得在没有测试机会的情况下提供这个很舒服,但是你可以尝试这样的事情......

flags=$(cut -f 9 -d ' ' /proc/30084/stat)
echo $(($flags & 0x40000000))

关于affinity - 检查 PF_NO_SETAFFINITY 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60100719/

相关文章:

c - MacOS : Scheduler affinity seems not to work

c++ - Windows Phone 中的进程关联

Java线程亲和性

kubernetes - 独家客户关系

android - 从广播接收器启动 Activity 会显示默认 Activity

android - singleInstance Activity 的任务亲和性?

multithreading - runtime.GOMAXPROCS 没有按预期工作

java - 在 python 和 java 中设置线程关联

c - 将大量线程固定到单个 CPU 会导致所有内核的利用率激增

windows - 识别特定线程使用的处理器(核心)