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);
}
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. I tried it on Solaris and Linux and got the same result. However HPUX did return 8000!
 
     
    