linux最大连接数
@ 安惪坔 · Wednesday, Nov 25, 2020 · 1 分钟阅读 · 更新于 Nov 25, 2020

ulimit -n 可设置的最大值是多少?

直接看源码吧

#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

#define __const_min(x, y) ((x) < (y) ? (x) : (y))
// 64位机
#define BITS_PER_LONG 64
int main(int argc, char *argv[])
{

        int sysctl_nr_open_max = __const_min(INT_MAX, ~(size_t)0/sizeof(void *)) & -BITS_PER_LONG;
        printf("The value of INT_MAX = %d\n", INT_MAX);
        printf("The value of INT_MIN = %d\n", INT_MIN);
        printf("The value of ulimit  = %d\n", sysctl_nr_open_max);
        // printf("~0 = %ud\n", (~(size_t)0)/sizeof(void *));
        // printf("-1 = %ud\n", (2*INT_MAX)+1);
        // printf("test = %d\n", (INT_MAX & -BITS_PER_LONG));
        return 0;
}

感谢

如果觉得我恰好对你有帮助,可以请我吃辣条!

wechat

It is better to attach some information or leave a message so that I can record the donation 📝, thank you very much 🙏.

关于我

一只肥宅,丑女,又宅又丑…

毕业院校: 白马书院

家庭住址: 大荒山无稽崖斜月三星洞