确定使用进程nodejs的CPU

时间:2015-11-21 17:34:15

标签: node.js macos child-process

有没有办法让哪些CPU正在执行子进程。我有8个CPU。所以父代码启动了8个子进程。这是节点代码:

    public interface DisplayValueListener<P>  {

         ...

         void setDisplayValue(P value, String reprValue);
    }

1 个答案:

答案 0 :(得分:0)

直接从child对象分叉但child_process没有。

但是,您可以使用其PID - child.pid - 并从节点执行例如UNIX ps -p <PID> -o psr命令来解析其响应。 PSR是特定进程中使用的处理器的编号。

为此,您可以根据需要调整node.js shell command execution中提议的解决方案:

function cmd_exec(cmd, args, cb_stdout, cb_end) {
  var spawn = require('child_process').spawn,
    child = spawn(cmd, args),
    me = this;
  me.exit = 0;  // Send a cb to set 1 when cmd exits
  child.stdout.on('data', function (data) { cb_stdout(me, data) });
  child.stdout.on('end', function () { cb_end(me) });
}
foo = new cmd_exec('netstat', ['-rn'], 
  function (me, data) {me.stdout += data.toString();},
  function (me) {me.exit = 1;}
);
function log_console() {
  console.log(foo.stdout);
}
setTimeout(
  // wait 0.25 seconds and print the output
  log_console,
250);