linux開啟程序數測試
阿新 • • 發佈:2018-11-09
檢視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\n", count); sleep(SLEEPTIME); printf("child %d end\n", count); exit(0); } printf("parent:create %d child\n", count); } for (count = 0; count < MAXPROCESS; count++) { wait(); } exit(0); }