How to see list of child processes created by Fork and Spawn in nodejs ?
how to list child processes in nodejs
Asked Answered
Nodejs does not have a built-in way to do this. You would have to use various OS tools or 3rd party NPM libraries for doing this. For OS tools, you can either run commands at the command prompt yourself to manually list them or you can run a child_process that issues the process listing command (for your OS) and then capture that output into your node.js app. –
Papist
You can either create a list of ChildProcesses, since spawn and fork return ChildProcess you can append a new item to the list just after creating it.
Second option would be to execute a command like ps and parse it's output. 1st option seems better for me, because it will be os independent and you will avoid parsing ps
output manually. Also you will have the actuall ChildProcess class which could be usefull.
What should one do if one wants to end child_processes that have been create on anotehr nodeJS instance? –
Discourteous
@bluejayke I'd probably emit a signal to process from parent and handle it child process nodejs.org/api/… or nodejs.org/api/… –
Evvoia
but how does one get access to the child process if it wasn't created in that nodejs instance? Meaning if its already running from somewhere else and the ChildProcess instance isn't available in the current code? –
Discourteous
@bluejayke im afraid you will have to setup some kind of communication between processess, or easier solution - create some kind of a manager or a server which will have knowledge of all running processes –
Evvoia
© 2022 - 2024 — McMap. All rights reserved.