<div dir="ltr">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.<div><br></div><div>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:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div>#!/bin/bash</div></div><div><div>name=$1</div></div><div><div>shift</div></div><div><div>$name $*</div></div><div><div>pid=$!</div></div><div><div>while read line ; do</div></div><div><div>  :</div></div><div><div>done < /dev/stdin</div></div><div><div>kill -KILL $pid</div></div></blockquote><div><div><br></div><div>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.</div><div class="gmail_extra"><div><div class="gmail_signature"><div dir="ltr"><div><div><br></div><div><span style="font-size:13px"><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b>José Valim</b></span></div><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><div><span style="font-family:verdana,sans-serif;font-size:x-small"><a href="http://www.plataformatec.com.br/" style="color:rgb(42,93,176)" target="_blank">www.plataformatec.com.br</a></span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Skype: jv.ptec</span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Founder and Director of R&D</span></div><div><br></div></span></div></span></div></div></div></div></div></div></div></div>