# sysctl kernel.pid_max  
kernel.pid_max = 32768  
# sysctl -w kernel.pid_max=500  
kernel.pid_max = 500  

 

#include <unistd.h>  
#include <stdio.h>   
int main ()   
{   
    pid_t fpid; //fpid表示fork函数返回的值  
    int count=0;
    while(1) { 
        fpid=fork();   
        if (fpid < 0) {   
            printf("error in fork!\n");
            break;
        }
        else if (fpid == 0) {
            count++;
        } else {
        sleep(100);
        return 0;
        }
    }
    printf("count is %d\n", count);
    return 0;
}

 

# gcc test.c; ./a.out   
error in fork!  
count is 172  

 

相关文章:

  • 2021-11-17
  • 2021-11-21
  • 2021-08-25
  • 2022-01-22
  • 2022-01-17
  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-23
  • 2021-08-30
  • 2021-07-22
  • 2021-05-04
  • 2021-11-17
  • 2021-10-17
相关资源
相似解决方案