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

Paul Davis <>
Mon Mar 22 20:17:38 CET 2010


On Mon, Mar 22, 2010 at 3:00 PM, Jacob Vorreuter
<> 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
>
> Thanks,
>
> Jake
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>

Jacob,

We had to deal with that issue in CouchDB, although our solution isn't
extremely elegant [1]. That spawnkillable code basically echos the os
process id back to Erlang and then uses exec to replace itself with
the requested command. Well behaved processes are expected to still
close when they detect that their stdin has been closed.

It all seems less than ideal, so I'd also be quite interested if
someone knows of a better way to handle such things.

Paul Davis

[1] http://github.com/apache/couchdb/tree/trunk/src/couchdb/priv/spawnkillable/


More information about the erlang-questions mailing list