Limit physical memory per process

后端 未结 6 2157
独厮守ぢ
独厮守ぢ 2021-02-02 14:19

I am writing an algorithm to perform some external memory computations, i.e. where your input data does not fit into main memory and you have to consider the I/O complexity.

6条回答
  •  再見小時候
    2021-02-02 14:49

    As other posters have indicated already, setrlimit is the most probable solution, it controls the limits of all configurable aspects of a process environment. Use this command to see these individual settings on your shell process:

    ulimit -a
    

    The ones most pertinent to your scenario in the resulting output are as follows:

    data seg size           (kbytes, -d) unlimited
    max locked memory       (kbytes, -l) 64
    max memory size         (kbytes, -m) unlimited
    virtual memory          (kbytes, -v) unlimited
    

    Checkout the manual page for setrlimit ("man setrlimit"), it can be invoked programmatically from your C/C++ code. I have used it to good effect in the past for controlling stack size limits. (btw, there is no dedicated man page for ulimit, it's actually an embedded bash command, so it's in the bash man page.)

提交回复
热议问题