Loading

测试kernel.pid_max值

# 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  

 

posted @ 2017-08-09 17:39  宋某人  阅读(1984)  评论(0编辑  收藏  举报