从 Erlang 进行操作系统进程管理的最佳方法是什么?我需要能够生成子操作系统进程,写入子进程的标准输入,从标准输出和标准错误读取,发送终止信号,并获得退出代码的通知。我不认为这对于 erts 中的内容是可能的。
我了解 erlexec,但我不知道它是否稳定或是否有人实际使用它在愤怒中。还有其他选择吗,或者这是最好的选择?
What's the best way to do OS process management from Erlang? I need to be able to spawn child OS processes, write to the child's stdin, read from both stdout and stderr, send kill signals, and get notified of exit codes. I don't see that this is possible with what's in erts.
I know about erlexec, but I don't know if it's stable or if anyone is actually using it in anger. Are there any other options, or is that the best?
发布评论
评论(2)
Port 程序是实现此目的的最佳方法。端口程序是安全的,不会损害 Erlang VM,如果它们崩溃或行为不当,可以像任何其他 Erlang 进程一样被杀死并重新启动。
端口驱动程序是不同的,如果它们行为不当可能会导致整个 Erlang VM 崩溃。
Port programs are the best way to do this. Port programs are safe and won't harm the Erlang VM, and if they crash or mis-behave can be killed and restarted like any other Erlang process.
Port Drivers are different and if they mis-behave can bring down the entire Erlang VM.
在 Erlang 中,管理操作系统进程的标准方法是端口。
如果选项
exit_status
添加到 open_port:可以通过向端口发送消息或通过port_command 函数和 stdout 内容将作为消息发送。 (另请注意
open_port
的{line, L}
和{packet, N}
选项):Stderr 也可以重定向到 stdout:
但是您无法使用端口发送终止信号,但如果您通过向端口发送消息或调用 port_close 外部进程可以通过 SIGPIPE 信号退出。
In Erlang standard way to manage OS processes is ports.
Exit status of spawned OS process will be sent as a message if option
exit_status
added to open_port:Data can be written to stdin of spawned OS process by sending a message to port or by port_command function and stdout content will be sent as a message. (Note also
{line, L}
and{packet, N}
options ofopen_port
):Stderr also can be redirected to stdout:
However you can't send kill signals with ports but if you close port by sending a message to port or by calling port_close external process can exit by SIGPIPE signal.