查看linux默认打开最大打开进程数
具体参考:https://www.jb51.net/article/143667.htm
#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #define MAXPROCESS 65535 #define SLEEPTIME 60 int main(int argc, char **argv) { pid_t pid; int count = 0; int maxprocess = MAXPROCESS; if (argc == 2) { maxprocess = atoi(argv[1]); } for (count = 0; count < maxprocess; count++) { pid = fork(); if (pid < 0) { perror("fork error"); exit(1); } else if (pid == 0) { printf("child %d start ", count); sleep(SLEEPTIME); printf("child %d end ", count); exit(0); } printf("parent:create %d child ", count); } for (count = 0; count < MAXPROCESS; count++) { wait(); } exit(0); }