我可以从node.js设置ulimit吗? [英] Can I set ulimit from node.js?

查看:156
本文介绍了我可以从node.js设置ulimit吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想限制子进程不要写太多数据或占用太多CPU时间(无限循环).在C语言中,我将调用setrlimit(2)来做到这一点. node.js中是否有类似的东西?

I'd like to restrict child processes from writing too much data or taking up too much cpu time (infinite loop). In C, I'd call setrlimit(2) to do that. Is there something like this in node.js?

推荐答案

据我所知,没有提供setrlimit()功能的node.js扩展,但是您可以使用一个小的shell解决方法来解决该限制. :

As far as I know, there is no node.js extension that provides setrlimit() functionality, but you can work around the limitation with a small shell workaround hack:

/bin/sh -c "ulimit -t 100; exec /usr/bin/node /my/node/program.js"

像核心node.js一样,它现在不再支持setrlimit(),因为它支持Windows,并且不再是仅POSIX的框架:

Looks like core node.js will never have setrlimit() now that it supports Windows and is no longer a POSIX-only framework: https://github.com/joyent/node/pull/2143

更新:我将拒绝的Node补丁转换为单独的posix扩展模块,现在可以在 NPM Github .

Update: I converted the rejected Node patch into a separate posix extension module which is now available in NPM and Github.

这篇关于我可以从node.js设置ulimit吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆