Number of CPUs.
var numCPUs = require( '@stdlib/utils/num-cpus' );
Number of CPUs.
var n = numCPUs;
// returns <number>
- In a web browser, the number of CPUs is determined by querying the hardware concurrency API.
- Otherwise, the number of CPUs is determined via the os module.
var cluster = require( 'cluster' );
var numCPUs = require( '@stdlib/utils/num-cpus' );
var i;
function onTimeout() {
process.exit( 0 );
}
if ( cluster.isMaster ) {
for ( i = 0; i < numCPUs; i++ ) {
cluster.fork();
}
} else {
console.log( 'Worker %s. Process id: %d.', cluster.worker.id, cluster.worker.process.pid );
setTimeout( onTimeout, 1000 );
}
Usage: num-cpus [options]
Options:
-h, --help Print this message.
-V, --version Print the package version.
$ num-cpus
# => <number>