如何在只知道用于启动它的模块名称的情况下终止 Erlang 中的进程?
如何在只知道用于启动它的模块名称的情况下终止 Erlang 中的进程?
How do I kill a process in Erlang knowing only the module name used to start it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果是为了简单调试,您可以运行 pman:start(),然后查找进程(双击条目即可查看初始调用等详细信息)。然后你可以直接从 pman 杀死它。
否则,您可以使用 erlang:processes() 列出系统中的所有进程(我知道这很可怕),并对每个进程运行 erlang:process_info(Pid, initial_call) 以找到正确的进程。完成此操作后,只需使用 exit(Pid, Kill) 即可。
If it's for simple debugging, you could run pman:start(), and just look for the process (double-click on an entry to see details such as initial call). You can then kill it from pman directly.
Otherwise, you could use erlang:processes() to list all processes in the system (horrible, I know), and run erlang:process_info(Pid, initial_call) on each of them to find the right process. Once you've done that, just use exit(Pid, kill).
没有办法做到这一点。
您最好的选择是根据注册名称和/或进程的初始调用进行推测。
There is no way to do that.
Your best bet is to speculate based on the the registered name and/or the initial call of your processes.
即使该进程尚未注册,您仍然可以通过其他方式找到该进程。例如,您可以使用 pman (pman:start()) 等进程监视器查看,看看是否在那里找到它。 pman 允许您过滤许多标准,这可能会引导您找到正确的流程。或者你可以启动调试器,在模块中安装一个断点,下次进程执行某些操作时,它会被中断,调试器会弹出一个窗口,在标题栏中你可以读取该进程的PID被打断了。
一旦获得了 PID,就可以使用 pid(A, B, C)。在 shell 上伪造一个 PID 对象,并用它来终止进程。
You can still possibly find the process through other means, even if it's not registered. For instance, you could have a look with a process monitor like pman (pman:start()) and see if you find it there. pman allows you to filter for many criteria, which could lead you to the right process. Or you could start up the debugger, install a breakpoint into the module, and next time the process does something, it will be interrupted, the debugger will pop up a window, and in the title bar you can read the PID of the process that was interrupted.
Once you have the PID, you can use pid(A, B, C). to forge a PID object on the shell from it, and use that to kill the process.