{"id":212,"date":"2013-02-13T07:42:56","date_gmt":"2013-02-13T07:42:56","guid":{"rendered":"http:\/\/tech.nes.aau.at\/?p=212"},"modified":"2013-02-13T07:47:11","modified_gmt":"2013-02-13T07:47:11","slug":"how-to-test-the-thread-limit-on-linux","status":"publish","type":"post","link":"https:\/\/tech.nes.aau.at\/?p=212","title":{"rendered":"How to test the thread limit on Linux"},"content":{"rendered":"<p>\/* compile with:   gcc -pthread -o thread-limit thread-limit.c *\/<br \/>\n\/* originally from: http:\/\/www.volano.com\/linuxnotes.html *\/<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;pthread.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<\/p>\n<p>#define MAX_THREADS 100000<br \/>\nint i;<\/p>\n<p>void run(void) {<br \/>\nchar c;<br \/>\nif (i &lt; 10)<br \/>\nprintf(&#8220;Address of c = %u KB\\n&#8221;, (unsigned int) &amp;c \/ 1024);<br \/>\nsleep(60 * 60);<br \/>\n}<\/p>\n<p>int main(int argc, char *argv[]) {<br \/>\nint rc = 0;<br \/>\npthread_t thread[MAX_THREADS];<br \/>\nprintf(&#8220;Creating threads &#8230;\\n&#8221;);<br \/>\nfor (i = 0; i &lt; MAX_THREADS &amp;&amp; rc == 0; i++) {<br \/>\nrc = pthread_create(&amp;(thread[i]), NULL, (void *) &amp;run, NULL);<br \/>\nif (rc == 0) {<br \/>\npthread_detach(thread[i]);<br \/>\nif ((i + 1) % 1000 == 0)<br \/>\nprintf(&#8220;%i threads so far &#8230;\\n&#8221;, i + 1);<br \/>\n}<br \/>\nelse<br \/>\nprintf(&#8220;Failed with return code %i creating thread %i.\\n&#8221;,<br \/>\nrc, i + 1);<br \/>\n}<br \/>\nexit(0);<br \/>\n}<\/p>\n<h2>Additional information<\/h2>\n<p>If you are an administrator of a server, you can configure various limits in \/etc\/security\/limits.conf<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/* compile with: gcc -pthread -o thread-limit thread-limit.c *\/ \/* originally from: http:\/\/www.volano.com\/linuxnotes.html *\/ #include &lt;stdio.h&gt; #include &lt;unistd.h&gt; #include &lt;pthread.h&gt; #include &lt;stdlib.h&gt; #define MAX_THREADS 100000 int i; void run(void) { char c; if (i &lt; 10) printf(&#8220;Address of c = &hellip; <a href=\"https:\/\/tech.nes.aau.at\/?p=212\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,27],"tags":[19,26,17,15],"class_list":["post-212","post","type-post","status-publish","format-standard","hentry","category-server","category-tips","tag-linux-text","tag-programming","tag-tool","tag-useful"],"_links":{"self":[{"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=\/wp\/v2\/posts\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=212"}],"version-history":[{"count":4,"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=\/wp\/v2\/posts\/212\/revisions"}],"predecessor-version":[{"id":215,"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=\/wp\/v2\/posts\/212\/revisions\/215"}],"wp:attachment":[{"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}