[erlang-questions] Stopping a port from within erlang

Michael McDaniel erlangx@REDACTED
Wed Aug 29 21:13:07 CEST 2007

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] ),

	{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
  {Port, {data, Data}} ->
       blah blah 

==> when time to cleanup 

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


> 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@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> !DSPAM:52,46d5bfb673321047272708!

Michael McDaniel
Portland, Oregon, USA
+1 503 283 5284

More information about the erlang-questions mailing list