[erlang-questions] open_port CPU "leak"

Kevin q2h46uw02@REDACTED
Tue Nov 4 07:16:07 CET 2008


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.




More information about the erlang-questions mailing list