[erlang-questions] open_port CPU "leak"

Bengt Kleberg <>
Tue Nov 4 07:36:36 CET 2008


Greetings,

A suggestion, in case that it is the result of "echo <Str> | sha1sum" 
that interests you (as opposed to open_port/2).

Have you tried os:cmd/1?


bengt

Those were the days...
    EPO guidelines 1978: "If the contribution to the known art resides
    solely in a computer program then the subject matter is not
    patentable in whatever manner it may be presented in the claims."


On 2008-11-04 07:16, 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.
> 
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list