[erlang-questions] open_port CPU "leak"

Carsten Schultz carsten@REDACTED
Tue Nov 4 11:00:46 CET 2008


On Tue, Nov 04, 2008 at 01:16:07AM -0500, Kevin wrote:
> 
> Hello, this function I wrote slowly increases CPU usage if called in a 
> fairly tight loop.  Even replacing Command
> with "echo hello" will not fix the problem.  I also tried called 
> port_close but I got a weird error, I think because
> the port was already closed.  Is this the way its done?  So far I've 
> found no better explanation in the books or docs? 
> Thanks for any feedback.
> 
> get_sha(Str) ->
> 
>     Command = "echo '" ++ Str ++ "' | sha1sum",
>     Port = open_port({spawn, Command}, [exit_status]),
>     Port ! {self(), {command, []}},
>     receive
>     {Port, {data, Data}} ->
>             %% chop off junk at end of sha1sum output, what is that crap???
>             string:substr(Data, 1, string:len(Data)-4);
>          {Port, {exit_status, Status}} -> %% exited without a result
>             {error, Status}
>     end.

Are there other messages sent that you are not interested in and that might pile up in the mail box?  Try adding

          OtherMsg -> diagnostic output

Best,

Carsten

-- 
Carsten Schultz (2:38, 33:47)
http://carsten.codimi.de/
PGP/GPG key on the pgp.net key servers, 
fingerprint on my home page.



More information about the erlang-questions mailing list