文件描述符
文件描述符是由无符号整数表示的句柄(一般使用范围0~65535),进程使用它来标识打开的文件。文件描述符与包括相关信息(如文件的打开模式、文件的位置类型、文件的初始类型等)的文件对象相关联,这些信息被称作文件的上下文。
对于内核而言,所有打开的文件都是通过文件描述符引用的。当打开一个现有文件或者创建一个新文件时,内核向进程返回一个文件描述符。
按照惯例,UNIX系统shell使用文件描述符0与进程的标准输入相关联,文件描述符1与标准输出相关联,文件描述符2与标准错误输出相关联。
查看默认文件描述符
[root@muban ~]# ulimit -n
1024
调整文件描述符
调整方法1:
修改/etc/security/limits.conf配置
[root@muban ~]# echo '* - nofile 65535'>>/etc/security/limits.conf
[root@muban ~]# tail -1 /etc/security/limits.conf
* - nofile 65535
配置完成后,重新登录才会生效。
[root@muban ~]# ulimit -n
65535
cat /etc/security/limits.conf
#<type> can have the two values:
# - "soft" for enforcing the soft limits
# - "hard" for enforcing hard limits
# ( - 就表明同时设置了 soft 和 hard 的值)
#<item> can be one of the following:
# - nofile - max number of open files (打开文件的最大数目)
调整方法2:
ulimit -SHn
通过help ulimit 我们可以看到-SHn参数意义
-S use the ‘soft’ resource limit
-H use the ‘hard’ resource limit
-n the maximum number of open file descriptors (最大文件描述符)
临时改:
[root@muban ~]# ulimit -SHn 65535
[root@muban ~]# ulimit -n
65535
永久改:直接把ulimit -SHn 65535命令加入到开机自启动文件里面/etc/rc.local,每次开机启动的时候生效。
cat >>/etc/rc.local<<EOF
ulimit -SHn 65535
EOF
补充
cat有创建文件的功能,创建文件后,要以EOF或STOP结束;
还有向已存在的文件追加内容的功能。
‘> ‘是重定向,覆盖,’>> ‘追加重定向,不覆盖。
#创建文件,并为文件输入内容
[root@muban /]# cat >test.txt<<EOF
> test
> liyao
> EOF #退出编辑状态
#测试
[root@muban /]# cat test.txt
test
liyao
# 向已存在的文件追加内容
[root@muban /]# cat>> test.txt<<EOF
> I am studying Linux
> EOF
#测试
[root@muban /]# cat test.txt
test
liyao
I am studying Linux
ulimit -a 查看所有可以修改的内容。