Linux/Linux Shell Command

ulimit - 리눅스에서 자원(리소스)의 제한 설정 관련 명령어

드로니뚜벅이 2022. 4. 26. 06:27

일반 데스크톱 버전에서는 드문 일이겠지만 서버 버전에서는 자원 제한때문에 문제가 발생하는 경우가 있습니다. 즉, Ubuntu Desktop 배포판과 Ubuntu Server 배포판의 자원의 제한 설정값이 다르다는 거죠.

 

자원 최대 설정 값 확인 : ulimit -a

$ ulimit -a
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-m: resident set size (kbytes)      unlimited
-u: processes                       63219
-n: file descriptors                1024
-l: locked-in-memory size (kbytes)  65536
-v: address space (kbytes)          unlimited
-x: file locks                      unlimited
-i: pending signals                 63219
-q: bytes in POSIX msg queues       819200
-e: max nice                        0
-r: max rt priority                 0
-N 15:                              unlimited
$ ulimit -aH
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             unlimited
-c: core file size (blocks)         unlimited
-m: resident set size (kbytes)      unlimited
-u: processes                       63219
-n: file descriptors                1048576
-l: locked-in-memory size (kbytes)  65536
-v: address space (kbytes)          unlimited
-x: file locks                      unlimited
-i: pending signals                 63219
-q: bytes in POSIX msg queues       819200
-e: max nice                        0
-r: max rt priority                 0
-N 15:                              unlimited

$ ulimit -a 명령어는 새로운 프로그램을 생성하면 기본으로 적용되는 한도치를 보여줍니다.

$ ulimit -aH 명령어는 자원을 최대로 늘릴 수 있는 한도치를 보여줍니다.

 

설정은 어디서?

/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:
#        - a user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#        - NOTE: group and wildcard limits are not applied to root.
#          To apply a limit to the root user, <domain> must be
#          the literal username root.
#
#<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 file descriptors
#        - 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)
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#root            hard    core            100000
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#ftp             -       chroot          /ftp
#@student        -       maxlogins       4

# End of file
  • nproc : 프로세스 최대 개수 (number of processes)
  • nofile : 파일 열기 최대 개수 (number of open files)
  • 계정 당 생성한 프로세스 개수: $ ps -Led -o user | sort | uniq -c | sort -n
  • 계정 당 오픈한 파일 개수 : $ sudo sysctl -a | grep file-nr

위에서 설정 항목으로 표기된 nproc과 리눅스 명령어인 nproc은 다른 내용입니다.

$ nproc --all   // 시스템에 사용 가능한 혹은 설치된 처리 장치의 수
12

 

참고 사이트