Detailed explanation of ulimit command

ulimit is used to limit the resources available to each user, such as CPU, memory, handles, etc. The following takes CentOS 6.5 as an example to summarize.

1 View ulimit

Command format:

ulimit [-SHacdefilmnpqrstuvx]
  • Parameter S: Indicates the soft limit, when the limit value is exceeded, it will alarm
  • Parameter H: Indicates a hard limit, which must not exceed the limit value
  • Parameters a: will list all resource limits like:

Enter image description

  • Parameters c: When an error occurs in some programs, the system may write the program's information in memory into a file (for debugging), which is called a core file. This is to limit the maximum size of each core file
  • Parameters d: the maximum value of each process data segment
  • Parameters f: the maximum file size that the current shell can create
  • Parameters l: The maximum value of physical memory that can be locked
  • Parameters m: the maximum value of resident memory that can be used
  • Parameters n: the maximum number of file handles each process can open simultaneously
  • Parameters p: the maximum value of the pipe
  • Parameters s: the maximum value of the stack
  • Parameters t: the maximum time each process can use the CPU
  • Parameters u: the maximum number of concurrent processes running per user
  • Parameters v: the maximum virtual memory that the current shell can use

2 Modify ulimit

Command format:

ulimit [-SHcdefilmnpqrstuvx] [limit]

A limit can be adjusted by adding a limit value after the command to be viewed, but it is only valid for the current login shell.

The parameter Smeans setting the soft limit; the parameter Hmeans setting the hard limit; when neither is specified, it means setting both the soft limit and the hard limit to the specified values.

3 Permanently modify ulimit

The so-called permanent means that every time you log in to the shell, it will be reset according to the configuration ulimitto achieve the effect of permanent effect.

  • Step 1: Modify /etc/security/limits.conf

Add the following:

For the configuration of this file, please refer to the following

[root@CentOS646506 ~]# vim /etc/security/limits.conf
* hard nproc 64000
* soft nproc 64000
* hard nofile 64000
* soft nofile 64000

The above content indicates that the soft limit and hard limit of sum will be modified to 64000 at the same time -u.-n

  • Step 2: Modify /etc/pam.d/login

Add the following:

[root@CentOS646506 ~]# vim /etc/pam.d/login
session required pam_limits.so

pamThe above indicates that use management when logging in limit.

  • Step 3: Modify /etc/profile

Add the following

[root@CentOS646506 ~]# vim /etc/profile
ulimit -u 64000
ulimit -n 64000

Each time you log in to the shell, these two ulimitcommands are initially executed and made effective.

  • make the configuration take effect

Re-login or use source /etc/profiletakes effect immediately.

source causes the current shell to take effect on the contents of the specified file.

3.1 /etc/security/limits.conf configuration details

Format:

<domain> <type> <item> <value>
  • domainmeans the effective entity
    • username
    • You can also @groupspecify a user group by
    • Use *indicates default value
  • typeRefers to the type of restriction
    • softsoft limit
    • hardhard limit
  • itemLimit resources
    • coresameulimit -c
    • datasameulimit -d
    • fsizesameulimit -f
    • memlocsameulimit -l
    • nofilesameulimit -n
    • stacksameulimit -s
    • cpusameulimit -t
    • nprocsameulimit -u
    • maxloginsSpecify the number of users who can log in at the same time
    • maxsysloginsThe number of users who can log in to the system at the same time
    • priorityUser process running priority
    • locksThe maximum number of files a user can lock
    • sigpengdingsameulimit -i
    • msgqueuesameulimit -q

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324406255&siteId=291194637