[erlang-questions] open_port CPU "leak"

Daniel Wiik daniel.n.wiik@REDACTED
Tue Nov 4 08:13:54 CET 2008


Hi Kevin,
Have tried the crypto module?

Perhaps the crypto:sha/1 function will solve your problem in a faster and
safer way.

Best regards
/Daniel

On Tue, Nov 4, 2008 at 7:16 AM, Kevin <q2h46uw02@REDACTED> 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.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081104/74aaee97/attachment.htm>


More information about the erlang-questions mailing list