커피닉스, 시스템 엔지니어의 쉼터
  ulimit 사용법 (글 윤영한) 작성일 : 2003/12/11 01:34
 
  • 글쓴이 : 좋은진호 ( http://coffeenix.net/ )
  • 조회수 : 18573
     
    현재는 http://chongnux.klug.or.kr 이 아닌 http://chongnux.ilinuxbay.com/ (청눅스)
    _____________________________________________________________________

    작성자 : 윤영한 (shee@chongnux.klug.or.kr)
    홈페이지 : http://chongnux.klug.or.kr
    _____________________________________________________________________

    [ RedHat 7.2 ]
    - 한도에는 두가지 종류가 있다, 소프트 한도는 새로운 프로그램이 생성되면 디폴트로
    적용되는 한도이다. 하드 한도는 소프트 한도에서 최대 늘릴수 있는 한도 이다.
    하드 한도는 슈퍼유저에 의해서만 조정이 가능하지만 무한히 늘릴수 있는 것은
    아니다. 만약 고칠려면 커널에서 이 값을 조정해야 한다.
    기본 설정은 /etc/profile에서 ulimit가 아닌 다른 방법은 /etc/security/limit.conf
    화일을 이용하는 것도 좋은 방법이다.


    * 소프트 한도
    [root@vm_master etc]# ulimit -Sa
    core file size (blocks) 0 # 코어파일의 최대크기
    data seg size (kbytes) unlimited # 프로세스의 데이타 세그먼트 최대크기
    file size (blocks) unlimited # 쉘에서 생성되는 파일일 최대크기
    max locked memory (kbytes) unlimited
    max memory size (kbytes) unlimited # resident set size의 최대크기(메모리 최대크
    기)
    open files 1024 # open file descriptors의 최대 숫자(열수있
    는 최대파일수)

    # 하나의 프로
    세스당 최대 열수 있는 화일의 개수
    pipe size (512 bytes) 8 # 512-바이트 블락의 파이프 크기
    stack size (kbytes) 8192 # 프로세스의 스택 최대크기
    cpu time (seconds) unlimited # 총 누적된 CPU시간(초)
    max user processes 1024 # 단일 유저가 사용가능한 프로세스의 최대갯수
    # virtual memory (kbytes)
    unlimited # 쉘에서 사용가능한 가상 메모리의 최대용량

    *하드 한도

    [root@vm_master etc]# ulimit -Ha
    core file size (blocks) unlimited
    data seg size (kbytes) unlimited
    file size (blocks) unlimited
    max locked memory (kbytes) unlimited
    max memory size (kbytes) unlimited
    open files 1024
    pipe size (512 bytes) 8
    stack size (kbytes) unlimited
    cpu time (seconds) unlimited
    max user processes 1024
    virtual memory (kbytes) unlimited


    [사용 방법]

    ulimit [옵션] 값

    -a: 모든 제한 사항을 보여준다.
    -c: 최대 코어 파일 사이즈
    -d: 프로세스 데이터 세그먼트의 최대 크기
    -f: shell에 의해 만들어질 수 있는 파일의 최대 크기
    -s: 최대 스택 크기
    -p: 파이프 크기
    -n: 오픈 파일의 최대수
    -u: 프로세스 최대수
    -v: 최대 가상메모리의 량



    [ ulimit & 커널 소스 헤더 분석 ]

    [ /usr/src/linux-2.4.17/include/linux/fs.h ]

    /*
    * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
    * the file limit at runtime and only root can increase the per-process
    * nr_file rlimit, so it's safe to set up a ridiculously high absolute
    * upper limit on files-per-process.
    *
    * Some programs (notably those using select()) may have to be
    * recompiled to take full advantage of the new limits..
    */

    /* Fixed constants first: */


    /* 한 프로세스당 화일 수의 절대 한계점
    */
    #define NR_OPEN (1024*1024) /* Absolute upper limit on fd num */

    /* 한 유저가 열 수 있는 최대 화일수
    */
    #define INR_OPEN 1024 /* Initial setting for nfile rlimits
    */



    /* 시스템에서 동시에 열수 있는 최대 화일수 */
    #define NR_FILE 8192 /* this can well be larger on a larger
    system */
    /* /proc/sys/fs/file_max file-nr 값과 같다.

    [root@vm_master fs]# cat file-max
    8192
    [root@vm_master fs]# cat file-nr
    298 50 8192

    현재 할당되 화일 핸들수
    현재 할당된 화일 핸들중 사용중이 핸들수 최대 사용 할 수 있는 화일 핸들수

    [ /usr/src/linux-2.4.17/Documentation/filesystems/proc.txt ]
    [ /usr/src/linux-2.4.17/include/linux/limit.h ]

    #ifndef _LINUX_LIMITS_H
    #define _LINUX_LIMITS_H

    #define NR_OPEN 1024 # 한 프로세스당 열수 있는 파일수

    #define NGROUPS_MAX 32 /* supplemental group IDs are
    available */
    #define ARG_MAX 131072 /* # bytes of args + environ for exec
    () */
    #define CHILD_MAX 999 /* no limit :-) */
    #define OPEN_MAX 256 /* # open files a process may have */
    #define LINK_MAX 127 /* # links a file may have */
    #define MAX_CANON 255 /* size of the canonical input queue
    */
    #define MAX_INPUT 255 /* size of the type-ahead buffer */
    #define NAME_MAX 255 /* # chars in a file name */
    #define PATH_MAX 4095 /* # chars in a path name */
    #define PIPE_BUF 4096 /* # bytes in atomic write to a pipe
    */

    #define RTSIG_MAX 32

    #endif


    커피닉스, 시스템 엔지니어의 쉼터 / URL : http://coffeenix.net/board_view.php?bd_code=146