Fun with open_port

Gerd Flaig <>
Sat Mar 20 17:51:35 CET 2004


Hi,

the following module

   -module(dreck).
   -export([r/0]).
   
   r() ->
       Port = open_port({spawn, "/bin/true"}, [{line, 200}, exit_status]),
       receive
   	X ->
   	    X
       after 5000 ->
   	    timeout
       end.

exposes interesting behaviour:

   % erl
   Erlang (BEAM) emulator version 5.3 [source] [hipe] [threads:0]
   
   Eshell V5.3  (abort with ^G)
   1> dreck:r().
   {#Port<0.30>,{exit_status,0}}
   2> dreck:r().
   {#Port<0.32>,{exit_status,0}}
   3> dreck:r().
   {#Port<0.33>,{exit_status,0}}
   4> c(dreck).
   {ok,dreck}
   5> dreck:r().
   timeout
   6> dreck:r().
   {#Port<0.65>,{exit_status,0}}
   7> dreck:r().
   {#Port<0.66>,{exit_status,0}}
   8> dreck:r().
   {#Port<0.67>,{exit_status,0}}

Any ideas what might be causing this and how I can fix it? I've been
staring at the emulator source but have not yet understood how the
inner workings of open_port fit together. I've tested this on R9C
(Debian package version 1:9.2-5 and another test on the same package
version, but compiled locally. Same effect).

       Goodbyte, Gerd.
-- 
Gerd Flaig                     Technik                
Bei Schlund + Partner AG       Brauerstraße 48      D-76135 Karlsruhe
 Physics is like sex: sure, it may give some practical results,
 but that's not why we do it. -- Richard Feynman



More information about the erlang-questions mailing list