On Tue, Feb 08, 2005 at 09:39:17AM +0100, Ryszard Lach wrote:
> * how to determine if my system/application is running linux or POSIX
> threads
Your system can be "running" both libraries at the same time,
depending on flags to the dynamic loader, etc. The only sane way to
check is a runtime one
#include <stdio.h>
#include <unistd.h>
#include <alloca.h>
#include <string.h>
int isnptl (void)
{
size_t n = confstr (_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
if (n > 0)
{
char *buf = alloca (n);
confstr (_CS_GNU_LIBPTHREAD_VERSION, buf, n);
if (strstr (buf, "NPTL"))
return 1;
}
return 0;
}
int main(void)
{
printf("NPTL: %s\n", isnptl() ? "yes" : "no");
return 0;
}
> * how to determine limits of threads per system, threads per process and
> threads per user (hard compiled or set by PAM etc.)
I believe this is set by the ulimit of the number of processes. This
can be changed by ulimit -u or in something like /etc/security/limits.conf
> * how is related amount of available stack to number of threads, which
> process can create
Did you mean : how is the amount of available system memory for stacks
related to the number of threads? If you use the default stack size
that you get when you call pthread_create() you're going to run out of
memory pretty quickly. If you change down with
pthread_attr_setstacksize() you're going to be able to run many more
threads. However, you're still going to hit a kernel limit, see
kernel/fork.c:fork_init()
/*
* The default maximum number of threads is set to a safe
* value: the thread structures can take up at most half
* of memory.
*/
max_threads = mempages / (8 * THREAD_SIZE / PAGE_SIZE);
> * I'd like also really understand what 'ps' displays. Don't say 'read
> manual', because manual assumes that you really know what's going on
> in kernel and tells you only how to display it.
ps should only display the main thread. You need to pass something
like '-m' to show the sub-threads.
-i
ianw@gelato.unsw.edu.au
http://www.gelato.unsw.edu.au
Attachment:
signature.asc
Description: Digital signature