Ubuntu 16.04系统默认最大打开文件数为1024个
2016-06-08 22:39
369 查看
代码证明
1 #include <stdio.h> 2 #include <sys/types.h> 3 #include <fcntl.h> 4 #include <stdlib.h> 5 #include <unistd.h> 6 7 int main(int argc,char *argv[]){ 8 9 int fd; 10 char name[1024]; 11 int i = 0; 12 while(1){ 13 sprintf(name,"file%d",++i); 14 fd = open(name,O_CREAT,0777); //超过最大打开数时再打开会出错,返回-1 15 if (fd == -1){ 16 exit(1); 17 } 18 printf("%d ",i); 19 } 20 return 0; 21 }
运行代码
#gcc -o haha open.c #./haha
执行完成后会看到打印并创建了1021个文件,加上系统自带的0,1,2三个文件,总共为1024个
修改最大打开文件数
查看系统定义的默认限制值# ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 7674 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 7674 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
修改最大打开最大文件数
# ulimit -n 4096
查看系统可以设置的打开的最大文件数
# cat /proc/sys/fs/file-max 97267
相关文章推荐
- Ubuntu 默认壁纸历代记
- Ubuntu Remix Cinnamon 20.04 评测:Ubuntu 与 Cinnamon 的完美融合
- 关于Ubuntu 11.10启动提示waiting for the network configuration的问题
- 在 Ubuntu 桌面中使用文件和文件夹
- ubuntu下chrome无法同步问题解决
- Ubuntu Linux使用体验
- 使用 GNOME 优化工具自定义 Linux 桌面的 10 种方法
- 以Ubuntu 9.04为例 将工作环境迁移到 Linux
- VirtualBox虚拟机XP与宿主机Ubuntu互访共享文件夹
- 从USB安装Ubuntu Server 10.04.3 图文详解
- Ubuntu 15.04 正式版发布下载
- Linux-Ubuntu 10.04安装Cadence-ic610 方法总结图解
- Ubuntu 12.04和Windows 7双系统安装图解
- Ubuntu /home下中文目录如何修改成英文?
- 开机出现:grub rescue的修复方法
- Ubuntu连接Android真机调试
- 你应该选择 Ubuntu 还是 Fedora?
- 100 个最佳 Ubuntu 应用(中)
- 看看我的Ubuntu Linux截图
- Ubuntu 12.04 LTS服务器版安装过程及使用图解