[erlang-questions] Stopping spawned process

Erik Reitsma erlang@REDACTED
Mon Nov 30 19:17:55 CET 2009


I would prefer not to modify mplayer, so I found a way around the fact 
that mplayer does not terminate when its stdin is closed. I wrap the 
call to mplayer in a small script as follows:

#!/bin/sh
(cat && kill 0) | mplayer $*

This way I can still communicate with mplayer through stdin, (through 
the cat process). When stdin of cat is closed, it terminates. Then "kill 
0" will terminate the shell and all its children (i.e. the mplayer 
process). Only is I manyally kill the shell process, the mplayer process 
will not be killed when I terminate the Erlang VM, but I can live with 
that...

Thanks all for pointing me in this direction. Hopefully this solution 
will be helpful to others, or improved by others.

*Erik.

Garrett Smith wrote:
> On Sun, Nov 29, 2009 at 10:24 AM, Robert Virding <rvirding@REDACTED> wrote:
>   
>> When Erlang dies the stdin of the spawned process will be closed. If the
>> spawned process checks its stdin it should be able to detect that Erlang has
>> died (or the port has been closed).
>>     
>
> +1
>
> When running applications as ports, I specify a command line option to
> tell the app to run in a special "Erlang port" mode, which watches
> stdin and shuts down when it closes. It's hard to control the child
> process otherwise.
>
> Garrett
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>   



More information about the erlang-questions mailing list