监控java进程的快速可靠的方法是什么?

发布于 2024-10-31 09:11:38 字数 251 浏览 1 评论 0原文

我有一个进程将在另一个 jvm 中创建一个 java 进程。他们留在同一台机器上。

我的理解是两个进程运行在不同机器上的情况,一般可以通过故障检测器来完成。但目前它只是生成另一个进程(使用 Runtime.getRuntime())并将必要的参数传递给子进程。我能想到的是执行系统命令,例如 jps ...ps -ef | grep ... 什么会更好 检测与监视它的进程位于同一台机器上的java进程是否崩溃?

I have a process that will create a java process in another jvm. They stay on the same machine.

My understanding is in the case that two processes run on different machines, generally it can be done through failure detector. But at the moment it is just to spawn another process (Using Runtime.getRuntime()) and pass necessary arguments to the child process. What I can think of is to execute system command e.g. jps ... or ps -ef | grep ... What would be a better to
detect if a java process crashes which locates on the same machine with the process that monitor it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦回梦里 2024-11-07 09:11:38

Runtime.exec 方法返回一个Process。您可以通过此实例对进程进行一些控制:您可以终止它(destroy),等待其终止(waitFor)并在终止后获取其错误代码(>退出值)。

The Runtime.exec methods return a Process. You have some control over the process through this instance: you can kill it (destroy), wait for its termination (waitFor) and get its error code once terminated (exitValue).

神回复 2024-11-07 09:11:38

根据您想要执行的操作,Process 对象可能会起作用。

如果您想了解更多信息,我建议在它们之间打开套接字连接。这样您就可以随时获得更详细的状态。

我以前做过这个,而且可以通过几个非常小的课程来完成。只需在两端发送和接收文本行即可。

Depending on what you want to do, the Process object may work.

If you want more information, I suggest opening a socket connection between them. This way you can get more detailed status at any time.

I've done this before and it can be done with a couple incredibly small classes. Just send and receive lines of text on both ends.

无声情话 2024-11-07 09:11:38

我将使用在监视 pid 的盒子上运行的脚本,如果它崩溃,则会向父进程发出信号以启动新的子进程。通过信号或通过侦听管道/本地套接字。

I would use a script running on the box that monitors the pid and if it crashes signals the parent process to start up a new child process. Either through a signal or through a listening pipe/local socket.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文