#include #include #include #include #include #include static int dummy_fd(void) { return dup(fileno(stdin)); } static void *thread_proc(void *unused) { while (1) { sleep(1); } return NULL; } int main(int argc, char **argv) { int ret; pthread_attr_t attr; pthread_attr_init(&attr); if (argc > 1) { char *e; long argv_l = strtol(argv[1], &e, 0); if (e && *e != '\0') { fprintf(stderr, "not an number %s\n", argv[1]); return EXIT_FAILURE; } size_t req_stacksize = argv_l; ret = pthread_attr_setstacksize(&attr, req_stacksize); if (ret) { fprintf(stderr, "%ld: %s\n", argv_l, strerror(ret)); return EXIT_FAILURE; } } size_t stacksize; ret = pthread_attr_getstacksize(&attr, &stacksize); if (ret) { fprintf(stderr, "pthread_attr_getstacksize: %s\n", strerror(ret)); return EXIT_FAILURE; } printf("stacksize: %d\n", stacksize); int i; for (i = 0; i < 32768; i++) { ret = dummy_fd(); if (ret < 0) { ret = errno; fprintf(stderr, "%d: fd: %s\n", i, strerror(ret)); break; } pthread_t th; int ret = pthread_create(&th, &attr, thread_proc, NULL); if (ret) { fprintf(stderr, "%d: thread: %s\n", i, strerror(ret)); break; } usleep(10000); } return -1; }