Ulimit parameter Introduction

Source: Internet
Author: User
Tags posix

Linux for each user, the system limits its maximum number of processes. To improve performance, the maximum number of processes per Linux user can be set according to the device resource situation

You can use Ulimit-a to display the current various user process limits.
Below I set the maximum number of processes for a Linux user to 10,000:
Ulimit-u 10240
For Java applications that need to do many socket connections and leave them open,
It is best to modify the number of files that each process can open by using Ulimit-n xx, which is the default value of 1024.
Ulimit-n 4096 increase the number of files that can be opened by each process to 4096, with a default of 1024
Some of the important settings that other recommendations are set to unrestricted (unlimited) are:
Data segment Length: ulimit-d Unlimited
Maximum memory size: Ulimit-m Unlimited
Stack size: Ulimit-s Unlimited
CPU Time: Ulimit-t Unlimited
Virtual Memory: Ulimit-v Unlimited
  
Temporarily, applies to a shell session that is logged on through the Ulimit command.
Permanently, by adding a corresponding Ulimit statement to the file read by the login shell, the shell-specific user resource file, such as:

1), the maximum number of processes to unlock Linux system and the maximum file opening limit:
Vi/etc/security/limits.conf
# Add the following line
* Soft Noproc 11000
* Hard Noproc 11000
* Soft Nofile 4100
* Hard Nofile 4100
Description: * Represents for all users, Noproc is the maximum number of processes, Nofile is the maximum number of open files
2), let SSH accept login program login, easy to view ulimit-a resource limit in SSH client:
A, Vi/etc/ssh/sshd_config
Change the value of Userlogin to Yes and remove the # comment
B. Restart the SSHD service:
/etc/init.d/sshd restart
3), modify the environment variable files for all Linux users:
Vi/etc/profile
Ulimit-u 10000
Ulimit-n 4096
Ulimit-d Unlimited
Ulimit-m Unlimited
Ulimit-s Unlimited
Ulimit-t Unlimited
Ulimit-v Unlimited

Run #source/etc/profile after saving to make it effective

/**************************************

Sometimes in the program need to open multiple files for analysis, the system is generally the default number is 1024, (with ULIMIT-A can see) for normal use is enough, but for the program, it is too little.
Modify 2 files.


1./etc/security/limits.conf
Vi/etc/security/limits.conf
Plus:
* Soft Nofile 8192
* Hard Nofile 20480


2./etc/pam.d/login
Session required/lib/security/pam_limits.so
/**********
Also make sure that the/etc/pam.d/system-auth file has the following content
Session required/lib/security/$ISA/pam_limits.so
This line ensures that the system will enforce this restriction.


/***********
3. Bash_profile for general users.
#ulimit-N 1024
Re-login OK

ulimit
  =======================
 
Ulimit: Displays (or sets) the limits (limit) of the resources that the user can use. This restriction is divided into soft limit (current limit) and hard limit (upper limit), where the hard limit is the upper value of the soft limit, and the system resources used by the application do not exceed the corresponding soft limit, and any transcendence causes the process to terminate.


Parameter Description
Ulimited does not restrict the resources that users can use, but this setting is not valid for the maximum number of files that can be opened (max open files)
and the maximum number of processes that can run concurrently (max user processes)
-A Lists all current resource limits
-C sets the maximum value of the core file. Unit: Blocks
-D sets the maximum value of the data segment for a process. Unit: Kbytes
-F Shell creates file size maximum, in blocks
-H Specifies the hard limit for setting a given resource. If the user has root user rights, the hard limit can be increased. Any user can reduce the hard limit
-l maximum amount of physical memory that can be locked
-the maximum number of resident memory that can be used by-M: Kbytes
-N maximum files per process that can be opened at the same time
-P sets the maximum value of the pipe, in block, 1block=512bytes
-s Specifies the maximum value of the stack: Kbytes
-s Specifies that the soft limit is set for the given resource. The soft limit can be increased to the value of the hard limit. If both the-H and-s flags are unspecified, the limit applies to both
-T to specify the number of seconds to use per process, in seconds
-u can run the maximum number of concurrent processes
-V Shell can use the largest virtual memory, in Kbytes
-X

Example 1:

[root@localhost proc]# ulimit-a
Core file size (blocks,-c)
Data seg size (Kbytes,-D) unlimited
file size (blocks,-f) Unlimited
Pending signals (-i) 2047
Max locked Memory (Kbytes, L),
Max memory size (Kbytes,-m) u nlimited
Open Files (-N) 1024x768
Pipe Size (bytes,-p) 8
POSIX message queues (bytes,-q) 819200
Stack size ( Kbytes,-s) 8192
CPU time (seconds,-T) unlimited
MAX user Processes (-u) 2047
Virtual memory (Kbytes,-V) unlimi Ted
File Locks (-X) unlimited
[root@localhost proc]#

each line of the output is made up of resource names, (units, parameters of the Ulimit command), and soft limits. Explanation:
Parameter Description
The maximum value of the core file size core files is blocks, and the data segment of the
data seg size process can be arbitrarily large
file size file can be arbitrarily large
pending sign ALS has up to 2047 pending signals
Max locked memory The maximum value of a task's locked physical memory is 32kB
Max memory size The maximum value of a task's resident physical memory
open files A task can open up to 1024 files at the same time
pipe size pipe has a maximum space of 4096 bytes
POSIX message queues POSIX messages queue with a maximum value of 819200 bytes
Stack size The maximum value of the stack for the process is 8192 bytes
CPU time that is used by the CPUs for the process
MAX user processes the maximum number of processes (including threads) that the current user has open concurrently is 2047
virtual memory There is no limit to the maximum number of files that the
file locks can lock without limiting the maximum address space for a process

Example 2: Limit the size of a file with the Ulimit command, resulting in a failed copy command

[[Email Protected]]ls temp.txt
Ls:temp.txt: No file or directory
[[Email protected]]ulimit-f 1 #设置创建文件的最大块 (piece = 512 bytes)
[[Email Protected]]cat a.c > Temp.txt
File size exceeded limit

The size of the file a.c is 5002 bytes, and the size of the created file we set is 512 bytes x1 Block = 512 bytes

Ulimit Parameter Description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.