closing a port doesn't kill the connected process?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

closing a port doesn't kill the connected process?

Jacob Vorreuter
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:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: closing a port doesn't kill the connected process?

Paul Davis-3
On Mon, Mar 22, 2010 at 3:00 PM, Jacob Vorreuter
<[hidden email]> 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:[hidden email]
>
>

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/

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: closing a port doesn't kill the connected process?

Richard Andrews-5
In reply to this post by Jacob Vorreuter
On Tue, Mar 23, 2010 at 6:00 AM, Jacob Vorreuter
<[hidden email]> 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

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: closing a port doesn't kill the connected process?

Hynek Vychodil-2
In reply to this post by Paul Davis-3
I'm using similar approach. First thing which port process does is
sending its PID. Then I set monitor or other linked process to port
owner which kills port process if doesn't behave right. Well behaving
process is ended by protocol message. If BEAM exits, process should
receive SIGPIPE. Default behavior is die on SIGPIPE and well behaving
process should not override it. All this together should catch most of
cases. It is mine best.

On Mon, Mar 22, 2010 at 8:17 PM, Paul Davis <[hidden email]> wrote:

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



--
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill
your boss.  Be a data hero!
Try GoodData now for free: www.gooddata.com

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: closing a port doesn't kill the connected process?

Robert Virding
In reply to this post by Jacob Vorreuter
When the port is closed the spawned port should get an end-of-file on
its stdin. This is the "standard" way for the process to detect when
the port has been closed: an end-of-file on stdin.

Robert

On 22 March 2010 20:00, Jacob Vorreuter <[hidden email]> 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:[hidden email]
>
>

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: closing a port doesn't kill the connected process?

Andrew Stone-5
EOF detected by the client is what we use. It's been in production for a year now without a problem.

-Andrew



----- Original Message ----
From: Robert Virding <[hidden email]>
To: Jacob Vorreuter <[hidden email]>
Cc: Erlang-Questions Questions <[hidden email]>
Sent: Wed, March 24, 2010 12:47:54 AM
Subject: Re: [erlang-questions] closing a port doesn't kill the connected  process?

When the port is closed the spawned port should get an end-of-file on
its stdin. This is the "standard" way for the process to detect when
the port has been closed: an end-of-file on stdin.

Robert

On 22 March 2010 20:00, Jacob Vorreuter <[hidden email]> 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:[hidden email]
>
>

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]

________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:[hidden email]