[erlang-questions] How do you kill an OS process that was opened with open_port on a brutal_kill?

José Valim jose.valim@REDACTED
Fri Nov 25 11:27:09 CET 2016


If I remember correctly, the stdin of the program started with open_port
will be closed when the Erlang VM terminates. So if the OS process is
listening to stdin and exiting when the stdin closes, you don't need to
worry about terminating it.

When they don't do so, you can also write a script that spawns the OS
process and traverses stdin until it closes and then it terminates the OS
process when stdin closes. Something like:

#!/bin/bash
name=$1
shift
$name $*
pid=$!
while read line ; do
  :
done < /dev/stdin
kill -KILL $pid


If you save it as "wrap" then you can start your OS process as "wrap NAME
ARGS". This can be handy if you cannot rely on C/C++ extensions. If anyone
knows any drawback to such approach, I would love to hear.

*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161125/7c3a2d12/attachment.htm>


More information about the erlang-questions mailing list