Linux上创建进程据说消耗很少,这个一直是Linux的特点,于是就专门测试Linux创建进程的极限,测试代码如下:
//fork.c#include#include #include #include #define MAXPROCESS 65535#define SLEEPTIME 60int 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);}
评论列表()