我想启动和销毁一个系统进程。
我知道要启动一个进程,我可以使用System.cmd "my_app", [],但它不会返回应用程序的 pid,并且我无法销毁(杀死)它。
Elixir 有管理子进程的方法吗?
System.cmd您可以使用以下代替:
port = Port.open(
{:spawn_executable "my_app"},
[
{:args, args},
:stream,
:binary,
:exit_status,
:hide,
:use_stdio,
:stderr_to_stdout
]
)
Run Code Online (Sandbox Code Playgroud)
然后,您可以通过执行以下操作获取进程的 PID {:os_pid, pid} = Port.info(port, :os_pid),并且可以使用 杀死该进程System.cmd("kill #{pid}")。
Elixir 端口: https: //hexdocs.pm/elixir/Port.html
Erlang 端口和端口驱动程序:http://erlang.org/doc/reference_manual/ports.html
| 归档时间: |
|
| 查看次数: |
1385 次 |
| 最近记录: |