Reasons why modifying the maximum number of threads in Linux does not take effect

It may be that the new file was not recompiled.

Before changing the maximum number of processes a process can create

After changing the maximum number of processes that can be created by a process 

 

test code 

#include <iostream>
#include <unistd.h>
#include <sys/wait.h>
#include <string.h>
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>

using namespace std;

void *func(void *argv)
{
    // cout << "i am a new pthread, my tid is" << pthread_self() << endl;
    while (1)
    {
    }
}

int main()
{
    cout << "i am main pthread" << endl
         << "my tid is " << pthread_self() << endl;
    // pthread_t 不能用数组吗,应该是可以的,但是我此前实验代码有错误
    // pthread_t tid;
    int count = 0; // 计算创建了多少个线程
    for (int i = 0; i < 100000000000000000000; i++)
    {
        int ret = 0;
        pthread_t *pt = new pthread_t;
        count++;
        if (count % 100 == 0)
        {
            cout << count << endl;
        }
        // cout << "i am main pthread" << endl
        //      << "my tid is " << pthread_self() << endl;//

        // sleep(1);
        if (int ret = pthread_create(pt, NULL, func, NULL) != 0)
        {
            fprintf(stderr, "pthread_create : %s\n", strerror(ret));
            exit(EXIT_FAILURE);
        }
    }

    int ret = 3;
    fprintf(stderr, "pthread_create : %s\n", strerror(ret));

    for (;;)
    {
        cout << "i am main pthread" << endl;
        sleep(1);
    }
}

Guess you like

Origin blog.csdn.net/m0_74234485/article/details/132794924