Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set ulimit from node.js?

Tags:

node.js

ulimit

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?

like image 435
topskip Avatar asked Nov 28 '22 22:11

topskip


2 Answers

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"

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

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

like image 63
Mika Eloranta Avatar answered Dec 06 '22 20:12

Mika Eloranta


I think this newly-released module is just what you're looking for: https://github.com/melor/node-posix

like image 30
alessioalex Avatar answered Dec 06 '22 18:12

alessioalex