开发者

What does pid 0 mean for sched_setaffinity()

I'm seeing such code in nginx sourc开发者_开发知识库e:

    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);
    }

Why here pid is 0 instead of getpid()?


From the 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().)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜