检查 PF_NO_SETAFFINITY 的值
Check value of PF_NO_SETAFFINITY
是否可以判断 process/thread 是否设置了 PF_NO_SETAFFINITY
标志?我在一系列进程 ID 上 运行 任务集,有些正在抛出以下形式的错误:
taskset: failed to set pid 30's affinity: Invalid argument
我相信这是因为某些进程设置了 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 的详细信息:
- http://man7.org/linux/man-pages/man5/proc.5.html
- https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk65143
示例:
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))
是否可以判断 process/thread 是否设置了 PF_NO_SETAFFINITY
标志?我在一系列进程 ID 上 运行 任务集,有些正在抛出以下形式的错误:
taskset: failed to set pid 30's affinity: Invalid argument
我相信这是因为某些进程设置了 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 的详细信息:
- http://man7.org/linux/man-pages/man5/proc.5.html
- https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk65143
示例:
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))