Skip to content

Commit

Permalink
Merge #26
Browse files Browse the repository at this point in the history
  • Loading branch information
melor committed Nov 1, 2014
2 parents 27ce344 + f03cf79 commit 4ebe9d8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -168,6 +168,9 @@ signal.
`'nofile'` (RLIMIT_NOFILE) Specifies a value one greater than the maximum file
descriptor number that can be opened by this process.

`'nproc'` (RLIMIT_NPROC) The maximum number of processes (or, more precisely on Linux,
threads) that can be created by this process. *(Note: Only Linux, OS X, and BSDs support the 'nproc' resource limit. An error will be raised on unsupported platforms.)*

`'stack'` (RLIMIT_STACK) The maximum size of the process stack, in bytes. Upon
reaching this limit, a SIGSEGV signal is generated.

Expand Down
3 changes: 3 additions & 0 deletions src/posix.cc
Expand Up @@ -106,6 +106,9 @@ static const name_to_int_t rlimit_name_to_res[] = {
{ "data", RLIMIT_DATA },
{ "fsize", RLIMIT_FSIZE },
{ "nofile", RLIMIT_NOFILE },
#ifdef RLIMIT_NPROC
{ "nproc", RLIMIT_NPROC },
#endif
{ "stack", RLIMIT_STACK },
{ "as", RLIMIT_AS },
{ 0, 0 }
Expand Down
17 changes: 17 additions & 0 deletions test/unit/test-getrlimit.js
Expand Up @@ -7,10 +7,19 @@ var limits = [
"data",
"fsize",
"nofile",
"nproc",
"stack",
"as"
];

var unsupportedLimits = [];

if(['linux', 'darwin', 'freebsd'].indexOf(process.platform) !== -1) {
limits.push('nproc');
} else {
unsupportedLimits.push('nproc');
}

// getrlimit: invalid input args
try {
posix.getrlimit("foobar");
Expand All @@ -37,3 +46,11 @@ for(var i in limits) {
assert.equal(true, typeof limit.soft == 'number' || limit.soft === null);
assert.equal(true, typeof limit.hard == 'number' || limit.hard === null);
}

for(i in unsupportedLimits) {
try {
posix.getrlimit(unsupportedLimits[i]);
assert.ok(false);
}
catch(e) { }
}
17 changes: 17 additions & 0 deletions test/unit/test-setrlimit.js
Expand Up @@ -7,10 +7,19 @@ var limits = [
"data",
"fsize",
"nofile",
"nproc",
"stack",
"as"
];

var unsupportedLimits = [];

if(['linux', 'darwin', 'freebsd'].indexOf(process.platform) !== -1) {
limits.push('nproc');
} else {
unsupportedLimits.push('nproc');
}

// setrlimit: invalid input args
try {
posix.setrlimit();
Expand Down Expand Up @@ -61,3 +70,11 @@ for(var i in limits) {
console.log(limits[i] + " now: " + JSON.stringify(limit2));
}
}

for(i in unsupportedLimits) {
try {
posix.setrlimit(unsupportedLimits[i], {soft: 100});
assert.ok(false);
}
catch(e) { }
}

0 comments on commit 4ebe9d8

Please sign in to comment.