Razones por las que modificar el número máximo de subprocesos en Linux no surte efecto

Puede ser que el nuevo archivo no haya sido recompilado.

Antes de cambiar el número máximo de procesos que un proceso puede crear

Después de cambiar el número máximo de procesos que puede crear un proceso 

 

código de prueba 

#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);
    }
}

Supongo que te gusta

Origin blog.csdn.net/m0_74234485/article/details/132794924
Recomendado
Clasificación