ubuntu - 在linux怎么限制一个进程运行内存大小
PHP中文网
PHP中文网 2017-04-17 12:02:40
0
1
766

在运行一个命令的时候可以限制其消耗内存大小,我找到一个命令ulimit,但是他如果发现进程超过最大内存的话,会kill掉。这并不是我想要的,我希望只是限制使用最大内存,但不能kill掉。

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
阿神

Using ulimit is the right way to solve this problem.

If the memory is exceeded and you still don’t kill it, what should you do with the program? Let it continue to use memory? Then why limit the total memory~

If the command is written by yourself, and the memory can be reclaimed as long as it is notified externally, then you can consider making this command respond to a special message, such as SIGUSR1, and reclaim the memory after receiving it. Then write a monitor program to continuously check the memory usage through /proc/$PID, and send it a message once it exceeds the limit. However, it seems that the request of the questioner is an arbitrary command, so this method obviously does not work.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!