linux 文件句柄数

---查看系统默认的最大文件句柄数,系统默认是1024
# ulimit -n
1024

----查看当前进程打开了多少句柄数
# lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr|more
131 24204 
57 24244  
57 24231   ........
其中第一列是打开的句柄数,第二列是进程ID。
可以根据ID号来查看进程名。
# ps aef|grep 24204
nginx  24204 24162 99 16:15 ?    00:24:25 /usr/local/nginx/sbin/nginx -s

Linux有硬性限制和软性限制。可以通过ulimit来设定这两个参数。方法如下,以root用户运行以下命令:
# ulimit -HSn 4096
以上命令中,H指定了硬性大小,S指定了软性大小,n表示设定单个进程最大的打开文件句柄数量。个人觉得最好不要超过4096,毕竟打开的文件句柄数越多响应时间肯定会越慢。设定句柄数量后,系统重启后,又会恢复默认值。如果想永久保存下来,可以修改.bash_profile文件,可以修改 /etc/profile 把上面命令加到最后.
------------------------------------------------
lsof -n|awk '{print $2}'|sort|uniq -c|sort -nr|more
lsof: WARNING: can't stat() ext2 file system /noah/baidulinux/V2-0.0.10-opt/etc/mtab (deleted)
Output information may be incomplete.
lsof: WARNING: can't stat() ext2 file system /noah/baidulinux/V2-0.0.10-opt/etc/nsswitch.conf (deleted)
Output information may be incomplete.
lsof: WARNING: can't stat() ext2 file system /noah/baidulinux/V2-0.0.10-opt/etc/sudoers (deleted)
Output information may be incomplete.
3188 10534
3180 2779
522 1670
434 329
423 689
87 21889
59 16754
16 659
15 32311
11 32315
11 32313
11 32312
10 32317
10 32316
9 32314
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值