- 浏览: 4732675 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
bzhao:
你也应该可以这样:(not tested)./rbtunnel ...
在Bash脚本中怎么关闭文件描述符? -
bzhao:
如果有A进程原代码情况下,通过如下调用,把他的子进程继承关闭则 ...
在Bash脚本中怎么关闭文件描述符? -
Master-Gao:
楼主咋没分析下源码呢?
我使用过的Linux命令之dirname - 截取给定路径的目录部分 -
jiedushi:
tail -F 就可以吧
Linux下实时跟踪log4j日志文件的bash脚本 - 增强了tail -f的功能 -
java_is_new:
新手学习了,就是不明白为一个网卡配多个ip有什么用
我使用过的Linux命令之ifconfig - 网络配置命令
我使用过的Linux命令之ulimit - 在shell进程中限制系统资源
本文链接:http://codingstandards.iteye.com/blog/967718 (转载请注明出处)
用途说明
ulimit是一个shell内建命令,用于控制由shell启动的进程的可用资源(Provides control over the resources available to the shell and to processes started by it, on systems that allow such control.)。对资源的限制分为两种,一种是硬性限制,一种是软性限制。硬性限制一旦设定就不能增加(A hard limit cannot be increased once it is set),而软性限制可以增加到硬性控制为止(a soft limit may be increased up to the value of the hard limit)。Linux系统可以对多种资源的使用进行限制,比如允许创建的文件数、允许打开的文件数、是否允许生成core等。要注意的是,该设置只对当前shell进程的子进程产生作用,并不会影响其他shell进程。
最初接触到这个命令,是在从事C/C++开发时经常会出现段错误、断言错误之类的,但是Linux操作系统中默认是不生成core文件的,所以无法确切的知道问题出现的位置。因此,通常的做法就是修改/etc/profile中的那个ulimit设置,如下所示:
ulimit -S -c 0 > /dev/null 2>&1
通常把允许生成的core文件的大小改成100M之类的,比如:
ulimit -S -c 100000000 > /dev/null 2>&1
PS: 由于本人理解的错误,-c的数值单位其实是blocks,一般是1K。具体block size是多少,与具体的文件系统有关,大伙可以参考本文后面列出的参考资料。
常用参数
使用示例
示例一 与ulimit有关的帮助信息
[root@node34 root]# type -a ulimit
ulimit is a shell builtin
[root@node34 root]# help ulimit
ulimit: ulimit [-SHacdflmnpstuv] [limit]
Ulimit provides control over the resources available to processes
started by the shell, on systems that allow such control. If an
option is given, it is interpreted as follows:
-S use the `soft' resource limit
-H use the `hard' resource limit
-a all current limits are reported
-c the maximum size of core files created
-d the maximum size of a process's data segment
-f the maximum size of files created by the shell
-l the maximum size a process may lock into memory
-m the maximum resident set size
-n the maximum number of open file descriptors
-p the pipe buffer size
-s the maximum stack size
-t the maximum amount of cpu time in seconds
-u the maximum number of user processes
-v the size of virtual memory
If LIMIT is given, it is the new value of the specified resource;
the special LIMIT values `soft', `hard', and `unlimited' stand for
the current soft limit, the current hard limit, and no limit, respectively.
Otherwise, the current value of the specified resource is printed.
If no option is given, then -f is assumed. Values are in 1024-byte
increments, except for -t, which is in seconds, -p, which is in
increments of 512 bytes, and -u, which is an unscaled number of
processes.
[root@node34 root]# cat /etc/security/limits.conf
# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#<domain> <type> <item> <value>
#
#Where:
#<domain> can be:
# - an user name
# - a group name, with @group syntax
# - the wildcard *, for default entry
#
#<type> can have the two values:
# - "soft" for enforcing the soft limits
# - "hard" for enforcing hard limits
#
#<item> can be one of the following:
# - core - limits the core file size (KB)
# - data - max data size (KB)
# - fsize - maximum filesize (KB)
# - memlock - max locked-in-memory address space (KB)
# - nofile - max number of open files
# - rss - max resident set size (KB)
# - stack - max stack size (KB)
# - cpu - max CPU time (MIN)
# - nproc - max number of processes
# - as - address space limit
# - maxlogins - max number of logins for this user
# - priority - the priority to run user process with
# - locks - max number of file locks the user can hold
#
#<domain> <type> <item> <value>
#
#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@student - maxlogins 4
# End of file
[root@node34 root]#
示例二 打印当前的资源限制
[root@node34 root]# ulimit -H -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) 4
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) unlimited
cpu time (seconds, -t) unlimited
max user processes (-u) 2048
virtual memory (kbytes, -v) unlimited
[root@node34 root]# ulimit -S -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) 4
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 2048
virtual memory (kbytes, -v) unlimited
[root@node34 root]#
示例三 修改允许打开的文件数
[root@node34 root]# ulimit -n
1024
[root@node34 root]# ulimit -n 4096
[root@node34 root]# ulimit -n
4096
[root@node34 root]#
要永久修改,请参见后面的资料。
问题思考
相关资料
【1】developerWorks 中国 通过 ulimit 改善系统性能
http://www.ibm.com/developerworks/cn/linux/l-cn-ulimit/
【2】有意没思的专栏 linux修改ulimit应该注意的
http://blog.csdn.net/noizz/archive/2008/03/13/2177503.aspx
【3】走在路上的你。。。 查看linux blocksize 大小
http://blogold.chinaunix.net/u/11765/showart_235505.html
【4】好好学习,天天向上 解决linux打开文件数1024限制的解决办法
http://www.51testing.com/?uid-13956-action-viewspace-itemid-209988
【5】我家空间 Linux 用户进程可打开文件数 TCP连接数 限制修改
http://www.myhomespace.net/p/2010/11/528
发表评论
-
在Linux用tar归档压缩文件时忽略某些文件和目录
2013-02-01 10:19 16927在Linux下,常用tar对文 ... -
使用nmap扫描服务器端口的一次操作
2012-11-01 17:00 15075使用nmap扫描服务器端口的一次操作 本文来自:http ... -
我使用过的Linux命令之wget - ooo
2011-09-14 13:10 0我使用过的Linux命令之wg ... -
推荐一篇学习Vim使用的好文:酷壳 - 简明 Vim 练级攻略
2011-09-09 12:53 9084简明 Vim 练级攻略 http://coolshell.c ... -
推荐一篇学习Vim使用的好文:酷壳 - 简明 Vim 练级攻略
2011-09-09 12:49 1简明 Vim 练级攻略 http://coolshell.c ... -
我使用过的Linux命令之:(冒号) - 啥也不做(除了……)
2011-08-29 13:18 11984我使用过的Linux命令之: ... -
我使用过的Linux命令之date - 显示、修改系统日期时间
2011-08-25 09:21 41905我使用过的Linux命令之da ... -
我使用过的Linux命令之declare - 声明shell变量(不知道没关系、知道了就更好的内建命令)
2011-08-16 09:22 21740我使用过的Linux命令之declare - 声明shell变 ... -
我使用过的Linux命令之alias - 设置命令的别名,让 Linux 命令更简练
2011-08-11 09:31 28716我使用过的Linux命令之alias - 设置命令的别名,让 ... -
我使用过的Linux命令之ar - 创建静态库.a文件
2011-08-08 10:40 51816我使用过的Linux命令之ar - 创建静态库.a文件 本 ... -
我使用过的Linux命令之crontab - 设置例行任务(类似于Windows中的任务计划)
2011-08-04 22:26 9691我使用过的Linux命令之crontab - 设置例行任务(类 ... -
我使用过的Linux命令之chmod - 改变文件/目录的访问权限
2011-08-03 21:33 10641我使用过的Linux命令之chmod - 改变文件/目录的访问 ... -
我使用过的Linux命令之export - 设置或显示环境变量
2011-08-02 19:55 25370我使用过的Linux命令之export - 设置或显示环境变量 ... -
我使用过的Linux命令之wc - 统计文件行数、单词数或字节数
2011-07-26 10:50 28933我使用过的Linux命令之wc - 统计文件行数、单词数或字节 ... -
我使用过的Linux命令之groupdel - 删除群组
2011-07-22 22:13 9620我使用过的Linux命令之gr ... -
我使用过的Linux命令之ifconfig - 网络配置命令
2011-07-21 20:43 60374我使用过的Linux命令之ifconfig - 网络配置命令 ... -
我使用过的Linux命令之ll - 列出文件/目录的详细信息
2011-07-20 21:22 7104我使用过的Linux命令之ll ... -
我使用过的Linux命令之mkdir - 创建目录
2011-07-20 20:58 13605我使用过的Linux命令之mkdir - 创建目录 本文链 ... -
我使用过的Linux命令之perror - 解释错误代码
2011-07-18 20:29 24968我使用过的Linux命令之perror - 解释错误代码 ... -
我使用过的Linux命令之ping - 测试与目标主机的连通性
2011-07-16 10:46 26256我使用过的Linux命令之ping - 测试与目标主机的连通性 ...
相关推荐
Linux ulimit命令用于控制shell程序的资源。 ulimit为shell内建指令,可用来控制shell执行程序的资源。 语法 ulimit [-aHS][-c ][-d ][-f ][-m ][-n ][-p ][-s ][-t ][-u ][-v ] 参数: -a 显示目前资源限制的设定...
为提高性能,可以根据设备资源情况,设置各linux用户的最大进程数,我们可以用ulimit来显示当前的各种用户进程限制。 ulimit为shell内建命令,可用来控制shell执行程序的资源。 语法格式:ulimit [参数] 常用参数...
linux_ulimit的使用 linux_ulimit的使用 linux_ulimit的使用
通常我们通过终端连接到linux系统后执行ulimit -n 命令可以看到本次登录的session其文件描述符的限制,如下: $ulimit -n 1024 当然可以通过ulimit -SHn 102400 命令来修改该限制,但这个变更只对当前的...
2.1.13 使用exec或ok来执行shell命令 19 2.1.14 find命令的例子 20 2.2 xargs 20 2.3 小结 21 第3章 后台执行命令 22 3.1 cron和crontab 22 3.1.1 crontab的域 22 3.1.2 crontab条目举例 23 3.1.3 crontab命令选项 ...
实验楼 - 免费提供了Linux在线环境,不用在自己机子上装系统也可以学习Linux,超方便实用。 鸟哥的linux私房菜 - 非常适合Linux入门初学者看的教程。 Linux公社 - Linux相关的新闻...
linux的最大进程句柄数设置在Linux下,我们使用ulimit -n命令可以看到单个进程能够打开的最大文件句柄数量(socket连接也算在里面)。系统默认值1024。
19.6 在shell中使用函数 204 19.7 创建函数文件 204 19.8 定位文件 205 19.9 检查载入函数 205 19.10 执行shell函数 205 19.10.1 删除shell函数 206 19.10.2 编辑shell函数 206 19.10.3 函数举例 207 19.10.4 将函数...
本书共分五部分,详细介绍了shell编程技巧,各种UNIX命令及语法,还涉及了UNIX下的文字处理以及少量的系统管理问题。本书内容全面、文字简洁流畅,适合Shell编程人员学习、参考。 目 录 译者序 前言 第一部分 shell...
19.6 在shell中使用函数 204 19.7 创建函数文件 204 19.8 定位文件 205 19.9 检查载入函数 205 19.10 执行shell函数 205 19.10.1 删除shell函数 206 19.10.2 编辑shell函数 206 19.10.3 函数举例 207 19.10.4 将函数...
shell 命令 show 命令 showmount 命令 shutacct 命令 shutdown 命令 size 命令 skulker 命令 slattach 命令 sleep 命令 slibclean 命令 sliplogin 命令 slocal 命令 smcaprop 命令 smdefca 命令 smdemon.cleanu 命令...
注意:在Linux终端下使用ulimit -a查看下一个文件并发数,默认是600,需通过 ulimit -n 60000修改后在允许脚本 在ONU或路由上行创建一个 WEB服务器,尽量使局域网内存的用户访问的网址的大小大一点,效果容易出现; ...
本书共分五部分,详细介绍了shell编程技巧,各种UNIX命令及语法,还涉及了UNIX下的文字处理以及少量的系统管理问题。本书内容全面、文字简洁流畅,适合Shell编程人员学习、参考。 目 录 译者序 前言 第一部分 ...
linux shell编程 教程大全 目 录 译者序 前言 第一部分 shell 第1章 文件安全与权限 1 1.1 文件 1 1.2 文件类型 2 1.3 权限 2 1.4 改变权限位 4 1.4.1 符号模式 4 1.4.2 chmod命令举例 5 1.4.3 绝对模式 5 1.4.4 ...
设置Linux打开文件句柄/proc/sys/fs/file-max和ulimit -n的区别表示系统级别的能够打开的文件句柄的数量.是对整个系统的限制,并不是
本书共分五部分,详细介绍了shell编程技巧,各种UNIX命令及语法,还涉及了UNIX下的文字处理以及少量的系统管理问题。本书内容全面、文字简洁流畅,适合Shell编程人员学习、参考。 目 录 译者序 前言 第一部分 ...
2.1.13 使用exec或ok来执行shell命令 19 2.1.14 find命令的例子 20 2.2 xargs 20 2.3 小结 21 第3章 后台执行命令 22 3.1 cron和crontab 22 3.1.1 crontab的域 22 3.1.2 crontab条目举例 23 3.1.3 crontab命令选项 ...
详细的介绍了Linux下的编程指南 目 录 译者序 前言 第一部分 shell 第1章 文件安全与权限 1 1.1 文件 1 1.2 文件类型 2 1.3 权限 2 1.4 改变权限位 4 1.4.1 符号模式 4 1.4.2 chmod命令举例 5 1.4.3 绝对...