【问题标题】:parent child process in nodeJSnodeJS中的父子进程
【发布时间】:2011-08-14 19:40:30
【问题描述】:

如何为以下简单的 C 代码创建等效的 NodeJS?

int main(int argc, char *argv[]) {
    if (fork()) {
        printf("I'm parent %d", getpid());
        printf("From parent : %d", 1+1);    
    } else {
        printf("I'm child %d", getpid());
        printf("From child : %d", 10+20);
    }

    return 0;
}

【问题讨论】:

标签: c node.js fork


【解决方案1】:

NodeJS docs 中查看Child Processes。然后查看Forever 作为如何使用它们的示例。

【讨论】:

    【解决方案2】:

    您需要使用 Web Workers API。它是在服务器中生成后台进程的标准。

    对于 Nodejs,我们有以下库 >

    https://github.com/cramforce/node-worker

    【讨论】:

      猜你喜欢
      • 2017-04-21
      • 2017-08-09
      • 2018-03-19
      • 1970-01-01
      • 2017-04-15
      • 2013-08-11
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      相关资源
      最近更新 更多