gpt4 book ai didi

c - pid 0 对 sched_setaffinity() 意味着什么

转载 作者:行者123 更新时间:2023-12-04 06:24:01 24 4
gpt4 key购买 nike

我在 nginx source 中看到这样的代码:

    if (sched_setaffinity(0, 32, (cpu_set_t *) &cpu_affinity) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"sched_setaffinity(0x%08Xl) failed", cpu_affinity);
}

为什么在这里 pid0而不是 getpid() ?

最佳答案

来自 sched_setaffinity(2) manpage :

The affinity mask is actually a per-thread attribute that can be adjusted independently for each of the threads in a thread group. The value returned from a call to gettid(2) can be passed in the argument pid. Specifying pid as 0 will set the attribute for the calling thread, and passing the value returned from a call to getpid(2) will set the attribute for the main thread of the thread group. (If you are using the POSIX threads API, then use pthread_setaffinity_np(3) instead of sched_setaffinity().)

关于c - pid 0 对 sched_setaffinity() 意味着什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6234368/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com