Maximum number of threads in a Linux System

Source: Internet
Author: User

The maximum number of threads for a process depends on three factors: the thread stack size, the maximum memory size of the process, and the number of operating system digits.
View system default values:
[Root @ c0109 ~] # Cat/proc/sys/kernel/threads-max
57709

Adjust the stack size:
[Root @ c0109 ~] # Ulimit-S

Modify the default value:

[Root @ c0109 ~] # Echo XXX>/proc/sys/kernel/threads-max

Test:

# Include <stdio. h> # include <pthread. h> # include <sys/Wait. h> void * Foo () {While (1) sleep (1) ;}int main () {int I = 0; pthread_t thread; while (1) {If (pthread_create (& Thread, null, Foo, null )! = 0) {printf ("thread create failed! \ N "); return 1;} printf (" % d \ n ", ++ I);} return 0 ;}

Compile:

Gcc-O test. C-lpthread

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.