简体   繁体   中英

How do Node.js based process managers work?

Using Forever or PM2 as examples, how exactly do node.js based process managers work?

I've looked at the code for each, but it seems to be spread out amongst a bunch of files and it's hard to follow.

More specifically, when you run something like 'pm2 stop foo.js' how does the program you're running interfaces with the background daemon? Is it running some bash stuff too?

They don't run bash, but they do write files to the filesystem. Forever writes socket files for the forever cli to communicate with the workers. Forever also writes files which contain the process's id (pid). I'm not sure what the pid's are used for, perhaps they are mostly for backwards compatibility and allowing a user friendly interface. It basically iterates over the files in the socket/ folder and communicate with the other processes over those sockets. PM2's implementation may be slightly different, but the idea is the same.

So the background daemon is running a server.listen() command which the cli will communicate with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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