Ulimit: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
No edit summary
Line 5: Line 5:




'''To specify the ''type'' with ''ulimit'', we use ''-H'' (hard) and ''-S'' (soft), where''' ''-H'' sets hard limits, while ''-S'' sets soft limits. By default, without either flag, ''-S'' is presumed
'''To specify the ''type'' with ''ulimit'', we use ''-H'' (hard) and ''-S'' (soft), where''' ''-H'' sets hard limits, while ''-S'' sets soft limits. By default, without either flag, ''-S'' is presumed<ref>https://linuxhint.com/linux_ulimit_command/</ref>


== Soft limit ==
== Soft limit ==

Revision as of 18:19, 16 June 2023

ulimit is a built-in Linux shell command that allows viewing or limiting system resource amounts that individual users consume. Limiting resource usage is valuable in environments with multiple users and system performance issues.


limits.conf file is a configuration file that defines the system resource allocation settings ulimit uses. The full path to the configuration file is /etc/security/limits.conf. Changing the values in the file persist after system reboot.


To specify the type with ulimit, we use -H (hard) and -S (soft), where -H sets hard limits, while -S sets soft limits. By default, without either flag, -S is presumed[1]

Soft limit

The soft limit is manageable by any user, and its maximum value cannot exceed the hard limit. The hard limit acts as a ceiling for the soft limit.

ulimit -Sa

Hard Limit

The hard resource limit defines physical resource limit for a user. At the same time, the hard limit is the maximum value for soft limit. Only root users are allowed to change the hard limit.

ulimit -Ha

Flag

The ulimit command takes the following general syntax

ulimit [flags][limit]

Flag Description
-H The hard limit for the given resource. Only root users can raise the hard limit, and any process can lower it.
-S The soft limit for the given resource. Any process can change the soft limit.
-a Lists all current resource limits.
-b The maximum socket buffer size.
-c The core dump size, expressed in the number of 512-byte blocks.
-d The data area size, in kilobytes.
-e The highest process scheduling priority (nice).
-f The file size limit in blocks when using the [limit] parameter. Not specifying a [limit] instructs the command to report the file size limit.
-i The pending signal number limit.
-k The queue allocation number limit.
-l The maximum size allowed for locking in memory.
-m The physical memory size, in kilobytes.
-n The maximum number of file descriptors that a process can have.
-p The pipe buffer size.
-P The maximum number of pseudoterminals.
-q The maximum number of bytes in POSIX message queues.
-r The maximum number of threads a process can have.
-R The maximum process running time, expressed in microseconds.
-s The stack size, in kilobytes.
-t Specifies a process' maximum running time, in seconds.
-T The thread number limit.
-u Specifies how many processes a user can create.
-v The maximum virtual memory available for processes.
-x The maximum number of file locks.

Example

#limit the process number to 10
ulimit -u 10

#limits the file size to 50KB
ulimit -f 50

#limits the virtual memory available for a process to 1000KB
ulimit -v 1000

#limits the number of open files to five
ulimit -n 5

limit keywords

  • 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 (KB)
  • maxlogins – max number of logins for this user
  • maxsyslogins – max number of logins on the system
  • priority – the priority to run user process with
  • locks – max number of file locks the user can hold
  • sigpending – max number of pending signals
  • msgqueue – max memory used by POSIX message queues (bytes)
  • nice – max nice priority allowed to raise to values: [-20, 19]
  • rtprio – max realtime priority
  • chroot – change root to directory (Debian-specific)

Reference