Erlang Mailing Lists

Author Message

<  Erlang questions mailing list  ~  Stopping spawned process

Guest
Posted: Sun Nov 29, 2009 1:58 pm Reply with quote
Guest
Hi all,

When I spawn an external process using open_port/2, and then I stop the
Erlang VM, the spawned process is not terminated. For example, when I do
the following the xterm remains.


Erlang R13B01 (erts-5.7.2) [source] [64-bit] [smp:4:4] [rq:4]
[async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.7.2 (abort with ^G)
1> open_port({spawn_executable,"/usr/bin/xterm"},[]).
#Port<0.424>
2>
User switch command
--> q


Is there a way to have the spawned processes terminated when the Erlang
VM terminates?

Regards,
*Erik.

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

Post received from mailinglist
maxlapshin
Posted: Sun Nov 29, 2009 2:02 pm Reply with quote
User Joined: 15 Sep 2009 Posts: 159
There is no guaranteed way to kill child process in common unix =(
Maybe another process watcher.

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

Post received from mailinglist
View user's profile Send private message Send e-mail
Guest
Posted: Sun Nov 29, 2009 2:32 pm Reply with quote
Guest
I checked what happens with other languages. In Python the behavior is
similar to in Erlang, when I use subprocess.Popen: the child process
stays alive when the Python process terminates. In Java, however, the
child process is killed. Probably a list of child processes is
maintained, and the children are sent a kill signal when the JVM is
killed. In Erlang I do not get direct access to the PID of the child,
neither do I get the opportunity to do anything when Erlang terminates
(or do I?).

Another process watcher would be a bit heavy for my purpose: a wrapper
around mplayer, as a client to a DVB-S media server.

Max Lapshin wrote:
> There is no guaranteed way to kill child process in common unix =(
> Maybe another process watcher.
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>


________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

Post received from mailinglist
maxlapshin
Posted: Sun Nov 29, 2009 2:40 pm Reply with quote
User Joined: 15 Sep 2009 Posts: 159
Yes, Erlang is poor in handling forked processes.
It is hard to kill spawned process, impossible to get its stderr,
impossible to chain
processes via pipe();


However, there is still no warranty even with Java that child process
will be killed.

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

Post received from mailinglist
View user's profile Send private message Send e-mail
rvirding
Posted: Sun Nov 29, 2009 4:25 pm Reply with quote
User Joined: 30 Aug 2006 Posts: 452 Location: Stockholm, Sweden
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).

Robert

2009/11/29 Max Lapshin <max.lapshin@gmail.com>

> Yes, Erlang is poor in handling forked processes.
> It is hard to kill spawned process, impossible to get its stderr,
> impossible to chain
> processes via pipe();
>
>
> However, there is still no warranty even with Java that child process
> will be killed.
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>


Post received from mailinglist
View user's profile Send private message Visit poster's website MSN Messenger
Guest
Posted: Sun Nov 29, 2009 5:01 pm Reply with quote
Guest
Hello,

What about taking the following steps:

1. spawn the child process using a bash/whatever script which writes the ID
of the process to a file in a specific directory and then runs mplayer;
2. launch your application also using a script, so that when the VM dies or
your application closes, the script then checks that directory for PID files
then kills them one by one.

It is clunky but should get the job done reliably.

Andrew

On Sun, Nov 29, 2009 at 3:31 PM, Erik Reitsma <erlang@ernovation.com> wrote:

> I checked what happens with other languages. In Python the behavior is
> similar to in Erlang, when I use subprocess.Popen: the child process stays
> alive when the Python process terminates. In Java, however, the child
> process is killed. Probably a list of child processes is maintained, and the
> children are sent a kill signal when the JVM is killed. In Erlang I do not
> get direct access to the PID of the child, neither do I get the opportunity
> to do anything when Erlang terminates (or do I?).
>
> Another process watcher would be a bit heavy for my purpose: a wrapper
> around mplayer, as a client to a DVB-S media server.
>
>
> Max Lapshin wrote:
>
>> There is no guaranteed way to kill child process in common unix =(
>> Maybe another process watcher.
>>
>> ________________________________________________________________
>> erlang-questions mailing list. See http://www.erlang.org/faq.html
>> erlang-questions (at) erlang.org
>>
>>
>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>


Post received from mailinglist
gar1t
Posted: Mon Nov 30, 2009 6:57 am Reply with quote
User Joined: 11 Aug 2009 Posts: 55
On Sun, Nov 29, 2009 at 10:24 AM, Robert Virding <rvirding@gmail.com> 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

Post received from mailinglist
View user's profile Send private message
Guest
Posted: Mon Nov 30, 2009 6:19 pm Reply with quote
Guest
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@gmail.com> 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
>


________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

Post received from mailinglist
wuji
Posted: Thu Aug 23, 2012 7:27 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
in the meat.In addition to the Minneapolis flight, a needle needle [h2]replica designer *beep*[/h2] needle was discovered by a teenage passenger aboard a Delta
from Amsterdam to Atlanta. The teen would not surrender the the cheap Ralph Lauren the needle to authorities, who noted he told them that
planned to use it as evidence in a lawsuit.In a a [h4]cheap replica *beep*[/h4] a federal report on the incidents, it was noted that
teen was the son of a passenger aboard the flight flight [h4]replica Christian Louboutin[/h4] flight to Minneapolis who also found a needle in his
needles were reported found on two other flights, one by by Cheap Ralph Lauren Shirts by a crew member and another by a federal air
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum