問題描述
我可以以與操作系統無關的方式限制 Perl 進程使用的內存嗎? (Can I Iimit the memory used by a Perl process in an OS‑agnostic way?)
Is there an OS‑agnostic Perl module that puts a hard limit on the amount of virtual memory a process can use; e.g. so that the process will be killed if it starts eating up too much memory?
I see Apache::SizeLimit, which is obviously Apache specific; and Process::MaxSize, which requires you to call a check function (and also has a hacky way of checking process size).
I've used ulimit in the past, but it requires you (AFAIK) to have an extra launching process, and it is OS‑specific.
Thanks, Jon
‑‑‑‑‑
參考解法
方法 1:
I don't think perl can have any awareness of whether its memory usage is real or virtual. However if you remove real vs. virtual from your requirement, you could place a limit simply on the memory being used.
Devel::Size and Cache::SizeAwareMemoryCache might get you a bit closer, or BSD::Resource's setrlimit
.
(by Jonathan Swartz、Ether)