简体   繁体   English

仅使用pid向分叉的child_process传递消息

[英]Messaging a forked child_process with just the pid

I have a main process spawning child_processes for long jobs. 我有一个主要进程生成child_processes以进行长时间的工作。

I want to be able to poll the processes to get an update on the completion of the task, but all I have is their pid. 我希望能够轮询进程以获取任务完成的更新,但是我所拥有的只是它们的pid。 How can I send a message to a specific process in nodejs? 如何将消息发送到Node.js中的特定进程?

If you're using child_process.fork() ( which I'm assuming you are ), you can send a message to the child process using child.send() : http://nodejs.org/api/child_process.html#child_process_child_send_message_sendhandle 如果您使用的是child_process.fork()我假设您是 ),则可以使用child.send()向子进程发送消息: http : //nodejs.org/api/child_process.html# child_process_child_send_message_sendhandle

There's no way to retrieve a child process object given a PID directly, however. 但是,无法直接检索给定PID的子流程对象。

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

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