2017-01-06 3 views
0

프로세스가 Centos에서 할 수있는 최대 메모리를 제한하고 싶습니다. 프로세스가 사용 가능한 모든 메모리 또는 시스템의 다른 프로세스에 영향을주는 대부분의 메모리를 사용하여 종료되는 시나리오가있을 수 있습니다. 그러므로 나는 이것이 어떻게 제한 될 수 있는지 알고 싶다.프로세스가 Centos에서 사용할 수있는 최대 메모리를 제한하는 방법은 무엇입니까?

또한 프로세스의 메모리 사용을 제한하는 샘플 프로그램을 제공하고 도움이 될 수있는 다음 시나리오를 표시 할 수 있습니다.

  1. 설정 한도 내에서 요청 된 메모리가 할당되면 메모리 할당에 성공했습니다.
  2. 요청 된 메모리가 설정된 제한을 초과하면 메모리 할당에 실패했습니다.

고마워요은

+2

당신은 ulimit''에 모습을 갖고 싶어. – alk

+0

@alk가 말했듯이, [this] (http://ss64.com/bash/ulimit.html) –

+0

Ulimit은 전체 시스템에 대한 제한을 설정합니다. 하지만 특정 프로세스의 메모리 사용을 제한하고 싶었습니다. 이 경우 내 옵션은 무엇입니까? –

답변

0
ulimit can be used to limit memory utilization (among other things) 

Here is an example of setting memory usage so low that /bin/ls (which is larger than /bin/cat) no longer works, but /bin/cat still works. 

$ ls -lh /bin/ls /bin/cat 
-rwxr-xr-x 1 root root 25K May 24 2008 /bin/cat 
-rwxr-xr-x 1 root root 88K May 24 2008 /bin/ls 
$ date > test.txt 
$ ulimit -d 10000 -m 10000 -v 10000 
$ /bin/ls date.txt 
/bin/ls: error while loading shared libraries: libc.so.6: failed to map segment from shared object: Cannot allocate memory 
$ /bin/cat date.txt 
Thu Mar 26 11:51:16 PDT 2009 
$ 

Note: If I set the limits to 1000 kilobytes, neither program works, because they load libraries, which increase their size. above 1000 KB. 

-d data segment size 

-m max memory size 

-v virtual memory size 

Run ulimit -a to see all the resource caps ulimits can set.