Erlang:如何限制分配给进程的内存 [英] Erlang: How to limit the memory assigned to a process
问题描述
我要问的是是否有可能限制分配给特定进程的内存(堆或堆栈),以使该进程不能超过它. 也许像"process_flag(min_heap_size,MinHeapSize)"之类的东西,但是最大的堆.
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.
推荐答案
您可以将某种进程跟踪gen_server放在一起,该服务器定期检查分配的进程的内存占用量,并在超过一定数量时将其杀死.
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.
使用process_info(Pid, memory).
和exit(Pid, Reason)
调用的组合,这应该很容易管理.
Using a combination of process_info(Pid, memory).
and exit(Pid, Reason)
calls, this should be quite manageable.
这篇关于Erlang:如何限制分配给进程的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!