每个进程的最大线程数 - 的sysconf(_SC_THREAD_THREADS_MAX)失败 [英] Maximum number of threads per process - sysconf(_SC_THREAD_THREADS_MAX) failing

查看:1258
本文介绍了每个进程的最大线程数 - 的sysconf(_SC_THREAD_THREADS_MAX)失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个UNIX机器上的每个进程的最大线程数,并写了下面的code使用的sysconf:

I'm trying to find the maximum number of threads per process on a UNIX machine and wrote the code below to use sysconf:

#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int main() {
errno = 0;
long maxThreads = sysconf(_SC_THREAD_THREADS_MAX);
if (maxThreads == -1 && errno == 0)
{
    printf("the variable corresponding to _SC_THREAD_THREADS_MAX "
            "is associated with functionality that is not "
            "supported by the system\n");
    exit(1);
}
if (maxThreads == -1)
{
    printf("errno: %d\n", errno);
    exit(1);
}

printf ("max num threads per process: %ld\n", maxThreads);

exit(0);
}

可惜的sysconf()返回-1不改变错误号!有谁知道如何解决这个问题,最终是什么每个进程Pthreads中的最大值是多少?
谢谢

Unfortunately the sysconf() returns -1 without changing the errno! Does anyone know how to get around this problem and eventually what is the maximum number of Pthreads per process? Thanks

P.S。我试了一下Solaris和Linux上,得到了相同的结果。然而HPUX做回8000!

P.S. I tried it on Solaris and Linux and got the same result. However HPUX did return 8000!

推荐答案

据我的手册的sysconf 在我的Mac OSX 10.7.X:

According to my manual for sysconf on my Mac OSX 10.7.X:

如果调用的sysconf()不成功,返回-1,并errno设置为合适。否则,如果变量与不支持的功能相关,则返回-1,并将errno不被修改。否则,当前变量的值返回。

If the call to sysconf() is not successful, -1 is returned and errno is set appropriately. Otherwise, if the variable is associated with functionality that is not supported, -1 is returned and errno is not modified. Otherwise, the current variable value is returned.

在linux下它是不同的:

Under linux it is different:

如果名称是无效的,则返回-1,并设置errno为EINVAL。否则,返回的值是系统资源和errno的值不改变。在选项的情况下,如果查询选项可用,则返回一个正值,-1,如果它不是。在极限的情况下,-1意味着没有明确的限制。

If name is invalid, -1 is returned, and errno is set to EINVAL. Otherwise, the value returned is the value of the system resource and errno is not changed. In the case of options, a positive value is returned if a queried option is available, and -1 if it is not. In the case of limits, -1 means that there is no definite limit.

因此​​,它看起来像 _SC_THREAD_THREADS_MAX 不在这个架构有效sysconfig中的变量或者是没有限制的。或者,也许有对另一个定义-1 其它架构。你必须检查你试图去上班每种架构的手册。

So it looks like that _SC_THREAD_THREADS_MAX is not a valid sysconfig variable on that architecture or maybe there is no limit. Or maybe there is another definition for -1 on other architectures. You'll have to check the manual on each architecture you are trying to get to work.

如果 _SC_THREAD_THREADS_MAX 是无效的,那么你可能想尝试的过程,而不是线程。也许有一个最大的进程设置这也意味着最大线程数。

If _SC_THREAD_THREADS_MAX is not valid then you might want to try processes instead of threads. Maybe there is a max processes setting which also means max threads.

这篇关于每个进程的最大线程数 - 的sysconf(_SC_THREAD_THREADS_MAX)失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆