简体   繁体   English

nodeJS中的父子进程

[英]parent child process in nodeJS

How to Create NodeJS equivalent for the below simple C code?如何为以下简单的 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;
}

Check out Child Processes in the NodeJS docs .查看NodeJS 文档中的子进程 Then check out Forever as an example of how to use them.然后查看Forever作为如何使用它们的示例。

You need to use the Web Workers API.您需要使用 Web 工人 API。 It is the standard to spawn background processes in server.它是在服务器中生成后台进程的标准。

For Nodejs, we have the following library >对于 Nodejs,我们有以下库 >

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM