Erlang/OTP Forums

Author Message

<  Erlang questions mailing list  ~  Stopping a port from within erlang

Guest
Posted: Wed Aug 29, 2007 6:54 pm Reply with quote
Guest
I'm trying to wrap some legacy applications behind a gen_server interface to allow me to supervise them in an OTP fashion.
mmcdanie
Posted: Wed Aug 29, 2007 7:15 pm Reply with quote
User Joined: 18 Mar 2007 Posts: 28 Location: Portland, Oregon, U.S.A.
On Wed, Aug 29, 2007 at 02:49:00PM -0400, Jim Miller wrote:
> I'm trying to wrap some legacy applications behind a gen_server interface to
> allow me to supervise them in an OTP fashion. I can start the processes fine
> with the open_port but I'm looking for a way to stop the spawned application
> from within erlang. At the moment, when I terminate the gen_server wrapper
> that spawns the process it leaves the process running, even after I exit
> erlang.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Here's how I'm using open_port and killing the spawned process. You may be
able to use something similar. Platform specific as well.


my platform

$ uname -a
Linux delora 2.6.20-15-386 #2 Sun Apr 15 07:34:00 UTC 2007 i686 GNU/Linux


==> starting ...

{Port, Pid} = port(). % first received data from port should be Pid


port() ->
Port = open_port( {spawn, MyProgram}, [eof, exit_status, use_stdio, binary] ),

receive
{Portb, {data, Pid_with_linefeed}} ->
{ok, Pid, 1} =
regexp:gsub( binary_to_list(Pid_with_linefeed), "\n", "") end ,

{Port, Pid}
.



==> use the port with receive for the "real" data

receive
{Port, {data, Data}} ->
blah blah

...
end



==> when time to cleanup

os:cmd("/bin/kill -9 " ++ Pid).



~Michael


>
> Regretably I can't modify the spawned application to listen to a message from
> erlang and I'd rather not write another layer to do this. I'm currently using
> the open_port because the only other function os.Cmd isn't quite what I'm
> looking for. Is there something equivalent to exec?
>
> Thanks
>
> !DSPAM:52,46d5bfb673321047272708!

> _______________________________________________
> erlang-questions mailing list
> erlang-questions@erlang.org
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
> !DSPAM:52,46d5bfb673321047272708!


--
Michael McDaniel
Portland, Oregon, USA
http://autosys.us
+1 503 283 5284
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
View user's profile Send private message
klacke
Posted: Wed Aug 29, 2007 7:53 pm Reply with quote
User Joined: 28 Feb 2005 Posts: 138
Jim Miller wrote:
> I'm trying to wrap some legacy applications behind a gen_server
> interface to allow me to supervise them in an OTP fashion. I can start
> the processes fine with the open_port but I'm looking for a way to stop


4> open_port({spawn, "echo $$; sleep 1000"}, []).
#Port<0.105>
5> flush().
Shell got {#Port<0.105>,{data,"3578\n"}}
ok


Pick up the integer and then os:cmd("kill " ++ IntList)


/klacke
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
View user's profile Send private message AIM Address MSN Messenger

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