Erlang: How to limit the memory assigned to a proc

2019-05-06 02:25发布

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.

2条回答
我想做一个坏孩纸
2楼-- · 2019-05-06 02:52

You could use spawn_opt with max_heap_size

查看更多
等我变得足够好
3楼-- · 2019-05-06 02:58

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.

查看更多
登录 后发表回答