Erlang: How to limit the memory assigned to a process

北战南征 提交于 2019-12-07 10:43:37

问题


What I'm asking is if it's possible to limit memory (heap or stack) assigned to a specific process, so that this process can't exceed it. Maybe something like "process_flag(min_heap_size, MinHeapSize)", but for the maximum heap.


回答1:


You could put together some kind of process tracking gen_server that periodically checks assigned processes for memory footprint and kills them if it exceeds a certain amount.

Using a combination of process_info(Pid, memory). and exit(Pid, Reason) calls, this should be quite manageable.




回答2:


You could use spawn_opt with max_heap_size



来源:https://stackoverflow.com/questions/13699559/erlang-how-to-limit-the-memory-assigned-to-a-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!