将来的你会感谢现在努力的自己,骚年,趁年轻多努力学习 ------ Jasper_boy

linux打开进程数测试

查看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);
}

  

posted @ 2018-10-20 10:38  Jasper_boy  阅读(200)  评论(0编辑  收藏  举报