从 Nodejs 应用程序 (Linux) 中重新启动外部进程
假设我正在从命令行(而不是nodejs应用程序)运行一个进程:
myProcess doSomething --withParam1
我还在运行连接到此过程(RPC)的Nodejs应用程序。
node myApp
myProcess
将随机静止地无法正常工作而不会崩溃,而myApp
将检测到它。我需要myApp
才能重新启动myProcess
(杀死并重新开始)。重新启动myProcess
之后,myApp
也将使用pm2重新启动(我已经在处理Nodejs App的PM2重新启动零件 - 我的问题是我无法使用PM2重新启动myProcess
因为它不是nodejs应用程序)。另外,由于它是第三方软件,因此我无法更改myProcess
的代码。
如何从nodejs应用程序重新启动外部进程?
Say that I am running a process from the command line (NOT a nodejs app):
myProcess doSomething --withParam1
I am also running a nodejs app that connects to this process (rpc).
node myApp
myProcess
will randomly silently fail to work properly without crashing and myApp
will detect it. I need myApp
to be able to restart myProcess
(kill it and start it again). After I restarted myProcess
, myApp
will also restart itself using pm2 (I am already handling the pm2 restart part for the nodejs app - my issue is that I cannot use pm2 to restart myProcess
since it is not a nodejs app). Also, I cannot change the code of myProcess
since it is a 3rd party software.
How can I restart the external process from my nodejs app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终使用 process.kill.kill =“ https://nodejs.org/api/child_process.html” rel =“ nofollow noreferrer”>子进程重新启动它。
为了在杀死该过程之前找到该过程的PID,我使用了以下方式:
I ended up using process.kill to kill the process and nodejs child process to restart it.
To find the pid of the process before killing it, I used this: