码迷,mamicode.com
首页 > 系统相关 > 详细

linux打开进程数测试

时间:2018-10-20 11:51:22      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:查看   [1]   int   erro   roc   http   include   进程   net   

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

  

linux打开进程数测试

标签:查看   [1]   int   erro   roc   http   include   进程   net   

原文地址:https://www.cnblogs.com/shansongxian/p/9820858.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!