[erlang-questions] closing a port doesn't kill the connected process?

Richard Andrews bflatmaj7th@REDACTED
Mon Mar 22 23:59:24 CET 2010


On Tue, Mar 23, 2010 at 6:00 AM, Jacob Vorreuter
<jacob.vorreuter@REDACTED> wrote:
> I'm starting a redis server instance by opening an Erlang port.  When the Erlang process exits or I explicitly close the port the os process is not killed.  Is there a way to accomplish that?
>
> 1> Port = erlang:open_port({spawn, "redis-server"}, [binary, exit_status]).
> #Port<0.429>
> 2> erlang:port_close(Port).
> true
>
> $ ps -ax | grep redis-server
> 31374 ??         0:00.02 redis-server

If it's always UNIX perhaps you could insert a pipe forwarder process
which kills redis-server on EOF; and call:

open_port({spawn, "pipe-wrapper redis-server"}, [binary, nouse_stdio,
exit_status])

nouse_stdio would be required because pipe-wrapper would be talking
stdin/stdout to redis-server.

Implementing pipe-wrapper is up to you.

--
  Rich


More information about the erlang-questions mailing list