[erlang-questions] can a program launched with open_port({spawn, Cmd}, Options) remain running after the port closes?

Tim Watson <>
Thu Sep 27 14:41:21 CEST 2012


Guys,

On 27 Sep 2012, at 13:18, Erik Søe Sørensen wrote:
> 2012/9/27 Jesper Louis Andersen <>
> I remember this was something I had going. Let me dig code:
> 
> ----
> #!/bin/sh
> 
> (cat && kill 0) | opentracker $*
> Nice incantation. I was just about to suggest using a wrapper program, but I probably wouldn't have thought of that variation.
>  
> ----
> 
> So the trick is that the … && kill 0 part sends a kill signal to all processes in the current process group. This lets you stop another process since cat(1) understands what happens when stdin is closed and handles it accordingly.
> 
> I've only used it in tests though so it may need work for real programs
> Such as replacing "&&" with ";" ? :-)
> Just in case someone came along and killed the cat. (Can't at the moment imagine other scenarios where cat would exit with non-zero return values, but they probably exist.)
> 
> Also, replace $* with "$@" (including the quotes), for proper handling of parameters with spaces in them and such.

Thanks both of you, I guess that I could drop this in in front of the required invocation, so you get the required behaviour. The tricky part here is that the code calling open_port/2 is kind of a generic 'run a script and monitor things' process, so I'll need to experiment with this a bit. Thanks for the suggestions anyway - I'll certainly give this a try.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120927/fc057435/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 235 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120927/fc057435/attachment.bin>


More information about the erlang-questions mailing list