2009년 10월 7일 수요일

[Linux] ulimit

ulimit 사용법

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

ulimit
    사용자별 프로세스(태스크)와 사용 파일 수의 제한을 결정할 수 있는 ulimit이 있는데
    먼저 프롬프트에서 다음과 같이 입력해 보자.

    [root@malsik]# ulimit -a
        그러면 다음과 같은 결과가 출력될 것이다.

    core file size (blocks) 0
    data seg size (kbytes) unlimited
    file size (blocks) unlimited
    max memory size (kbytes) unlimited
    stack size (kbytes) 8192
    cpu time (seconds) unlimited
    max user processes 256
    pipe size (512 bytes) 8
    open files 1024
    virtual memory (kbytes) 2105343
    max user process의 값이 256인 것을 확인할 수 있다. 이 값을 무한대로 바꾸기
    위해서는 다음과 같이 한다.

    [root@malsik]# ulimit -u unlimited
        한 사용자가 열 수 있는 파일 수를 바꾸려면 다음과 같이 한다.

    [root2maso]# ulimit -n 4096
        다시 ulimit -a를 입력하면 변경된 사항을 살펴볼 수 있을 것이다. 설정하려는 값이
        항상 적용되기 위해서는 쉘 스크립트(/root/ .bashrc)에 사용한 명령어를 추가시켜 준다.

====================================================================

- 참고사항 -
[ 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

==================================================

#usr/src/linux~~/include/linux/posix_types.h

       FD_SETSIZE 값 8192로 변경      <--- 원격에서 ulimit -a  검색시 보여주는 형식


출처 : http://malsik2004.tistory.com/

댓글 없음:

댓글 쓰기