ulimint -a Used to display the current various user process restrictions
Linux For each user , The system limits its maximum number of processes , To improve performance , According to the equipment resources ,
Set up a Linux The maximum number of processes for the user , Some need to be set to unlimited :
Segment length :ulimit -d unlimited
Maximum memory size :ulimit -m unlimited
Stack size :ulimit -s unlimited

When we use this command, the main purpose is to produce core file , This is the file when the program runs with a distribution segment error :

ulimit -c unlimited

Generate core file ,

#######################################################
The following is from ;http://hi.baidu.com/jrckkyy/blog/item/2562320a5bdbc534b1351d95.html

Check out the restrictions ulimit -a

You can see the following information

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
pending signals                 (-i) 1024
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 4096
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

And what we need to change is open files (-n) 1024 Value

So the order is limit -n 2048( Set as you need )

-----------------------------------------------------------------------------------

Functional specifications : control shell Program resources .

language Law :ulimit [-aHS][-c <core File limit >][-d < Data section size >][-f < file size >][-m < Memory size >][-n < Number of files >][-p < Buffer size >][-s < Stack size >][-t <CPU Time >][-u < Number of programs >][-v < Virtual memory size >]

Additional explanation :ulimit by shell Built in instruction , Can be used to control shell Resources for executing programs .

ginseng Count :
   -a Display the current resource limit settings . 
   -c <core File limit > Set up core Maximum value of file , Unit: block . 
   -d < Data section size > The maximum value of the program data section , Unit is KB. 
   -f < file size > shell The largest file that can be created , Unit: block . 
   -H Set hard limits on resources , That is, the restrictions set by the administrator . 
   -m < Memory size > Specifies the maximum amount of memory available , Unit is KB. 
   -n < Number of files > Specifies the maximum number of files that can be opened at a time . 
   -p < Buffer size > Specifies the size of the pipeline buffer , Company 512 byte . 
   -s < Stack size > Specify the upper limit of the stack , Unit is KB. 
   -S Set elastic limits on resources . 
   -t <CPU Time > Appoint CPU The upper limit of usage time , The unit is in seconds . 
   -u < Number of programs > The maximum number of programs a user can open . 
   -v < Virtual memory size > Specifies the maximum amount of virtual memory that can be used , Unit is KB.

------------------

1, explain :
ulimit be used for shell Resources used to start the process .

2, Category :
shell Built in command

3, Grammar format :
ulimit [-acdfHlmnpsStvw] [size]

4, Parameter Introduction :

QUOTE:
-H Set hardware resource limits .
-S Set software resource limits .
-a Show all current resource constraints .
-c size: Set up core Maximum value of file . Company :blocks
-d size: Set the maximum value of the data segment . Company :kbytes
-f size: Set the maximum value of the created file . Company :blocks
-l size: Set the maximum number of processes locked in memory . Company :kbytes
-m size: Set the maximum amount of resident memory that can be used . Company :kbytes
-n size: Set the maximum number of file descriptors that the kernel can open at the same time . Company :n
-p size: Set the maximum value of the pipeline buffer . Company :kbytes
-s size: Set the maximum value of the stack . Company :kbytes
-t size: Set up CPU Maximum usage time limit . Company :seconds
-v size: Set the maximum virtual memory . Company :kbytes

5, Simple example :

1] stay RH8 Environmental documents of /etc/profile in , We can see how the system is configured ulimit Of :

CODE:
#grep ulimit /etc/profile
ulimit -S -c 0 > /dev/null 2>&1

This statement sets the requirements for software resources and for core File size settings

2] If we want to fight against shell Limit the size of the created file , Such as :

CODE:
#ll h
-rw-r--r-- 1 lee lee 150062 7 month 22 02:39 h
#ulimit -f 100 # Set the maximum block to create a file ( A piece of =512 byte )
#cat h>newh
File size limit exceeded
#ll newh
-rw-r--r-- 1 lee lee 51200 11 month 8 11:47 newh

file h Its size is 150062 byte , And the size of the created file we set is 512 byte x100 block =51200 byte
Of course, the system will generate according to your settings 51200 Bytes of newh file .

3] It can be like an example 1] equally , Put what you want to set ulimit Put it in /etc/profile In this environment file .

------------------------------------------------------------------------------------------------------------------

When some programs in the system encounter some errors and crash when , The system will automatically generate core File record crash Time system information , Including memory and register information , For programmer's Day after debug You can use . These errors include segment errors 、 Illegal order 、 Bus error or user generated exit message, etc , In a general way ,core Files are stored in the current folder .

core Files can sometimes happen when you make an error , Not in your current folder , There are two reasons for this : One is that the current terminal is set not to pop up core file ; The other is core The file is assigned a path .

For the former , We can use ulimit Command to core Set the size of the file . By default ,core The size of the file is set to 0, So the system doesn't dump Out core The file . At this time , Use command :ulimit -c unlimited Set it up , You can put the core The size of the file is set to infinity , You can also use numbers instead of unlimited, Yes core More precise setting of the upper limit of the file .

In addition to setting core Beyond the size of the file , You can also be right about core There are some rules about the name of the document . This setting is right /proc/sys/kernel/core_pattern and /proc/sys/kernel/core_uses_pid These two files are modified . The way to change these two files is as follows :

echo <pattern> > /proc/sys/kernel/core_pattern

echo <"0"/"1"> /proc/sys/kernel/core_uses_pid

And pay attention to , Only super users can modify these two tables .

core_pattern It is accepted that core The name of the file pattern, It contains any string , And use % Generate some identifiers as transfer symbols , by core Add special meaning to the name of the document . The defined identifiers are as follows :

%%: amount to %

%p: amount to <pid>

%u: amount to <uid>

%g: amount to <gid>

%s: It's equivalent to leading to dump The number of the signal

%t: amount to dump Time for

%e: Equivalent to the name of the executable file

%h: amount to hostname

In addition to the above flag bits , It also stipulates that :

1、 The single at the end % It can be removed directly ;

2、% Add any character other than the above ,% And the character will be removed ;

3、 All other characters are added to the name as normal characters ;

4、core The maximum name of a file is 64 Bytes ( Include '\0');

5、core_pattern In the default pattern by core;

6、 To maintain compatibility , By setting core_uses_pid, Can be in core Add... To the end of the document %p;

7、pattern Path information can be included in .

------------------------------------------------------------------------------------------------------------------

The following information is compiled from the Internet , The references are as follows :

http://blog.csdn.net/hanchaoman/archive/2009/08/03/4405655.aspx

http://www.mysys-admin.org/category/general/

1. It can be used ulimit -a Look at the size of the stack .
In the kernel 2.6.20 Next , stack size by 8192 kbytes
If there are no restrictions , The size of the stack is only limited by the memory .2G Is the upper limit .

2. core file
    * On or off core File generation
ulimit -c You can see if this option is turned on , if 0 Turn it off ;
ulimit -c 0 It can be closed manually
ulimit -c 1000 For settings core The maximum file size is 1000k

ulimit -c unlimited Set up core The file size is unlimited

Many systems turn off generation by default core Of documents , This command can be added to your profile In the middle

3. Set up Core Dump Core dump directory and naming rules for

By default , A lot of systems core The file is generated in the directory where you run the program , Or you're in the program chdir The last catalog , And then in core There's a... At the end of the file pid. In practice , This may cause a lot of directory generation core file , Not easy to manage , actually , stay 2.6 Next ,core The generation location of the file and the naming of the file name can be configured Of .

/proc/sys/kernel/core_uses_pid You can control what happens core Whether to add... To the file name of the file pid As an extension , If added, the file content is 1, Otherwise 0
proc/sys/kernel/core_pattern You can set the formatted core File save location or file name , For example, the original file content is core-%e
You can modify :
echo "/tmp/core-%e-%p" > core_pattern
Will control what's happening core The files will be stored in /corefile Under the table of contents , The resulting file is called core- Command name -pid- Time stamp
Here is a list of parameters :
    %p - insert pid into filename add to pid
    %u - insert current uid into filename Add current uid
    %g - insert current gid into filename Add current gid
    %s - insert signal that caused the coredump into the filename Adding results in core The signal of
    %t - insert UNIX time that the coredump occurred into filename add to core When the file is generated unix Time
    %h - insert hostname where the coredump happened into filename Add host name
    %e - insert coredumping executable name into filename Add command name

Of course , You can do it in the following ways
sysctl -w kernel.core_pattern=/tmp/core-%e-%p

These operations once the computer restarts , You'll lose , If you want to persist these operations , Can be in /etc/sysctl.conf Add to file :
kernel.core_pattern=/tmp/core%p

After that , If you don't want to restart to see the effect , Use the following command :
sysctl -p /etc/sysctl.conf

------------------------------------------------------------------------------------------------------------------

Expert advice :

Problem solved :
         There is a procedure P Running on the server for a long time , Now it's often every 1 God died once ( Segment error ).

The current solution :
         use SecureCRT Open a terminal , And set... On the service ulimit -c nulimited, And then start the program P. use ulimite -a The result of the command query is as follows :

core file size       (blocks, -c) unlimited
         data seg size           (kbytes, -d) unlimited
         file size             (blocks, -f) unlimited
         pending signals                 (-i) 1024
         max locked memory    (kbytes, -l) 32
          ............
         indicate core Files can be generated .

And test the use of kill -6 pid can core file .

The present difficulties :

When running ulimit -c nulimited terminal ( And the terminal will run the program P It's booted in the background ./P &) close , Program P It's not generated after death core file .
         It was found that ulimit The command is about the terminal .

Expert advice :
          How to set up to generate core file , It's not about the terminal
          namely , Program started , Turn off the terminal , When the program dies ( Segment error ) It can generate core file .

stay
/etc/security/limits.conf ( Set in redhat Derivative line linux)
or
/etc/profile Medium :
# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

Comment out the line above .

There's more UNIX Class operating system also has its own configuration file to set .

------------------------------------------------------------------------------------------------------------------

gdb core Multithreading
stay linux Debugging multithreading in the environment , It doesn't feel like .NET So convenient . I've been looking for a deadlock these days bug It's been a long time , Let's talk about the methods used .

Multithreading if dump, Most of them are segment errors , It usually involves illegal reading and writing of memory . You can do this , Use the following command to turn on the system switch , Let it be generated when it dies core file .   
ulimit -c unlimited
In this way, you can see it in the current directory when you die core.pid(pid For process number ) The file of . Then use gdb:
gdb ./bin ./core.pid 
After going in , Use bt Look at the stack when it's dead , In the use of frame command .

And there's a thread inside that stops , Not dead either , This is usually a deadlock or a timeout problem involving message acceptance ( Listen to what people say , Never met ). In this case , have access to :
gcore pid ( Debugging process pid Number )
Generate... Manually core file , In the use of pstack(linux It doesn't seem to work ) Look at the stack . If you can't see it , Just look at the code , See if it's if,return,break,continue This kind of statement operation is to forget to unlock , There is also the problem of nested locks , It needs to be analyzed .

Last , Say a word , Watch the code , It's no use beating your chest .

-------------------------------------

1, explain :
ulimit be used for shell Resources used to start the process .
2, Category :
shell Built in command
3, Grammar format :
ulimit [-acdfHlmnpsStvw] [size]
4, Parameter Introduction :
-H Set hardware resource limits .
-S Set software resource limits .
-a Show all current resource constraints .
-c size: Set up core Maximum value of file . Company :blocks
-d size: Set the maximum value of the data segment . Company :kbytes
-f size: Set the maximum value of the created file . Company :blocks
-l size: Set the maximum number of processes locked in memory . Company :kbytes
-m size: Set the maximum amount of resident memory that can be used . Company :kbytes
-n size: Set the maximum number of file descriptors that the kernel can open at the same time . Company :n
-p size: Set the maximum value of the pipeline buffer . Company :kbytes
-s size: Set the maximum value of the stack . Company :kbytes
-t size: Set up CPU Maximum usage time limit . Company :seconds
-v size: Set the maximum virtual memory . Company :kbytes 5, Simple example : 
5. give an example
stay Linux When writing programs , If the program is large , Come across “ Segment error ”(segmentation fault) Questions like this , This is mainly due to Linux The initial stack size of the system (stack size) It's too small , It's usually 10M. I usually put stack size Set to 256M, So there are no paragraph errors ! The order is :
ulimit   -s 262140 
If you want the system to remember this configuration automatically , Just edit /etc/profile file , stay “ulimit -S -c 0 > /dev/null 2>&1” Line down , add to “ulimit   -s 262140”, Just save and restart the system ! 
1] stay RH8 Environmental documents of /etc/profile in , We can see how the system is configured ulimit Of :
#grep ulimit /etc/profile
ulimit -S -c 0 > /dev/null 2>&1
This statement sets the requirements for software resources and for core File size settings
2] If we want to fight against shell Limit the size of the created file , Such as :
#ll h
-rw-r--r-- 1 lee lee 150062 7 month 22 02:39 h
#ulimit -f 100 # Set the maximum block to create a file ( A piece of =512 byte )
#cat h>newh
File size limit exceeded
#ll newh
-rw-r--r-- 1 lee lee 51200 11 month 8 11:47 newh
file h Its size is 150062 byte , And the size of the created file we set is 512 byte x100 block =51200 byte
Of course, the system will generate according to your settings 51200 Bytes of newh file .
3] It can be like an example 1] equally , Put what you want to set ulimit Put it in /etc/profile In this environment file .
purpose  
Set or report user resource limits .
grammar  
ulimit [ -H ] [ -S ] [ -a ] [ -c ] [ -d ] [ -f ] [ -m ] [ -n ] [ -s ] [ -t ] [ Limit ]
describe  
ulimit Command to set or report user process resource limits , Such as /etc/security/limits As defined in the document . The file contains the following default values : 
fsize = 2097151
core = 2097151
cpu = -1
data = 262144
rss = 65536
stack = 65536
nofiles = 2000 
When new users are added to the system , These values are used as default values . When adding users to the system , The above values are determined by mkuser Command settings , Or through chuser Command change . 
Limits are soft or hard . adopt ulimit command , The user can change the soft limit to the maximum setting value of the hard limit . To change the resource hard limit , Must have root User permissions . 
Many systems do not include one or more of these limits . The limit of a specific resource is to specify Limit Parameter setting .Limit The value of a parameter can be a number in a specified cell in each resource , Or value unlimited. To put a specific ulimit Set to unlimited, We can use the word unlimited. 
    notes : stay /etc/security/limits Setting the default limit in the file is setting the system width limit , Not just the limits that users need to create . 
Omit Limit When parameters are , Will print out the current resource limit . Unless the user specifies -H sign , Otherwise print out the soft limit . When the user specifies more than one resource , Limit names and units are printed before values . If no option is given , It is assumed that with -f sign . 
because ulimit Orders affect the current shell Environmental Science , So it will serve as shell General built-in commands provide . If you invoke the command in an independent command execution environment , Does not affect the file size limit of the caller environment . This is the case in the following example : 
nohup ulimit -f 10000
env ulimit 10000 
Once the hard limit is reduced through the process , If there is no root Privilege cannot be increased , It's impossible to return to the original value . 
More about user and system resource limits , Please see the AIX 5L Version 5.3 Technical Reference: Base Operating System and Extensions Volume 1 Medium getrlimit、setrlimit or vlimit Subroutines .
sign
-a     List all current resource limits .
-c     With 512 In byte blocks , Specify the size of the core dump .
-d     With K Specifies the size of the data area in bytes .
-f     Use Limit Parameter to set the file size limit ( In blocks ), Or report the file size limit when no parameters are specified . The default value is -f sign .
-H     Specifies to set the hard limit of a given resource . If the user owns root User permissions , You can increase the hard limit . Any user can reduce the hard limit .
-m     With K Specifies the size of the physical memory in bytes .
-n     Specify the limit of the number of file descriptors a process can have .
-s     With K Specifies the size of the stack in bytes .
-S     Specifies to set the soft limit for a given resource . The soft limit can be increased to the value of the hard limit . If -H and -S None of the signs specifies , The limit applies to both .
-t     Specify the number of seconds used by each process .
Exit state  
Return the following exit value :
0     Successfully completed .
>0     Refuse requests for higher limits , Or something goes wrong .
Example  
To set the file size limit to 51,200 byte , Input : 
ulimit -f 100

ulimit -c unlimited Use ( Reprint ) More articles about

  1. ulimit -c unlimited

    tomcat produce core journal : app:/usr/local/apache-tomcat-7.0.55_8082/logs# ulimit -a core file size (blocks, -c ...

  2. -bash: ulimit: max user processes: cannot modify limit: Operation not permitted

    install oracle It's time to create oracle After user , Switch oracle When users , To quote the following wrong [root@localhost ~]# su - oracle-bash: ulimit: max user proce ...

  3. ( turn )linux The maximum number of processes in the next process 、 Maximum number of threads 、 The number of files opened by the process and ulimit Command to modify the hardware resource limit

    ulimit Command to view and change system restrictions ulimit Detailed command ulimit be used for shell Resources used to start the process , Can be used to set system limits Grammar format ulimit [-acdfHlmnpsStvw] [size ...

  4. PHP The topics with high appearance rate in interview &lt; Reprint &gt;

    --------------------PHP part --------------------- PHP Several output functions in echo,print(),print_r(),sprintf(),var_dump() ...

  5. ulimit command

    Link to the original text linux The default is not to produce core Of documents , Use ulimit -c unlimited Let go of summary System performance has always been a hot topic , How to achieve the most effective performance tuning through the simplest settings , How to use limited resources ...

  6. linux ulimit tuning

    1, explain :ulimit be used for shell Resources used to start the process .2, Category :shell Built in command 3, Grammar format :ulimit [-acdfHlmnpsStvw] [size]4, Parameter Introduction :-H Set hardware resource limits . ...

  7. Optimize system resources ulimit《 High performance Linux Server building practice : Operation and maintenance monitoring 、 Performance tuning and cluster applications 》

    Optimize system resources ulimit< High performance Linux Server building practice : Operation and maintenance monitoring . Performance tuning and cluster applications > Suppose there's a situation like this , a Linux The host is logged in at the same time 10 Users , Without limiting system resources , this 10 ...

  8. linux adopt ulimit Improve system performance

    https://www.ibm.com/developerworks/cn/linux/l-cn-ulimit/ summary System performance has always been a hot topic , How to achieve the most effective performance tuning through the simplest settings , how ...

  9. linux Of ulimit command

    ulimit The command is used to limit system users to shell Access to resources . grammar : ulimit [-acdfHlmnpsStv] [size] Introduction to options :    -a Show all current resource constraints ;    -c size: ...

Random recommendation

  1. linux Source code installation program

    After downloading the source code tar zxvf file.tar.gz       Unzip the source code package ./configure --prefix=/opt/haha/   Install to this path make   compile sudo ma ...

  2. Exception in thread &quot;main&quot; java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli :

    1. matching jdk and maven Version of http://www.bubuko.com/infodetail-1757416.html      jdk1.6 To match maven3.2.5 maven Version download address : ...

  3. Codeforces 633C Spy Syndrome 2(DP + Trie Trees )

    The title is about an encrypted string , The encryption rule is to convert the original text into lowercase letters , Then the words are reversed , Finally, remove the space . Now for a few known words , Restore encrypted string . and UVa1401 A truth .. use dp[i] Before the encrypted character i Characters ...

  4. Android A collection of effects

    QQ Sideslip style :http://www.cnblogs.com/lichenwei/p/4111252.html, By inheritance HorizontalScrollView Class to implement .

  5. ordinary XML and JSON Data processing

    One .XML Change the format to json data format using System; using System.Collections.Generic; using System.Linq; using System.W ...

  6. ERROR: Got error reading packet from server: A slave with the same server_uuid/server_id as this slave has connected to the master

    centos7.5 do binlog-server, Pull the main library binlog Report errors problem : [root@db03-53 binlog]# mysqlbinlog -R --host=10.0.0.55 --u ...

  7. ios- Password judgment

    We often involve users or mobile phone number login in the project , At this time, the login will be successful only with the password . Next, I'd like to make some judgments about the form of mobile phone and password : - (void)registButtonClick:(id)sender { )// ...

  8. use Delphi Make a dynamic menu The article 《 use Delphi Make a dynamic menu 》

    --- Resume content start --- 1. First , Determine the data source of the dynamic menu , Make sure that the dynamic menu title comes from Windows System registry for , Or from a database , Or from a subdirectory , It depends on the function of the program . Let's assume that the main window is called Ma ...

  9. Linux CentOS 7.x/6.x/5.x Import epel Source

    How to Enable EPEL Repository for RHEL/CentOS 7.x/6.x/5.x vim /etc/yum.repos.d/CentOS-Base.repo uncomment ...

  10. Resolve errors :scandir() has been disabled for security reasons

    Server environment : LNMP When deploying code on the server . I met this problem . It hurts ! 2 terms of settlement :   open phpinfo.php , Search for : scandir find disabled_function, Verify that this function does not ...