Can I install ulimit from node.js?

I would like to limit child processes from writing too much data or take too much processor time (infinite loop). In C, I would call setrlimit (2) for this. Is there something similar in node.js?

+4
source share
3 answers

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

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

It looks like the node.js core will never be setrlimit() now that it supports Windows and is no longer the basis for POSIX only: https://github.com/joyent/node/pull/2143

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

+20
source

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

+4
source

I do not think there is a built-in method. However, you can sometimes check the memory usage of the process with process.memoryUsage () and kill the process manually.

Alternatively, if you know how much time is expected to run, you can specify a timeout, as described here .

+1
source

Source: https://habr.com/ru/post/1381351/


All Articles