测试当前机器可以创建多少线程

ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 3612
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 3612
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <errno.h>

#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <pthread.h>

void* threadWork(void* arg)
{
    while(1)
        sleep(1);
}

int main(int argc, char **argv)
{
    pthread_t thID;
    int i = 0;
    while(1)
    {
        int err = pthread_create(&thID,NULL,threadWork,NULL);
        if (err != 0)
        {
            printf("%s\n",strerror(err));
            exit(1);
        }
        printf("%d\n",i++);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/xiangtingshen/p/11967965.html