[erlang-questions] spawn problem

Matthias Lang <>
Tue Mar 27 09:10:04 CEST 2007


Fernando Ipar writes:
 > Hello all,
 > 
 > I'm writing a little module to make use of erlang's lightweight 
 > processes and load test external programs/servers.
 > 
 > Here's a very simple first version:
 > 
 > ---- code ----
 > test(_, 0) ->
 >         true;
 > 
 > 
 > test(Command, Threads) when number(Threads) ->
 >         spawn('os', 'cmd', [Command]),
 >         test(Command, Threads - 1).
 > 
 > 
 > start() ->
 >         Command = list_to_atom(os:getenv("Command")),
 >         Threads = list_to_integer(os:getenv("Threads")),
 >         test(Command,Threads).
 > 
 > --- end code ----

In addition to what's already been said, the above doesn't really make
use of erlang's lightweight processes. Each time you call os:cmd,
you're starting a (heavyweight) operating system process.

It may be that this is what you intended.

Matthias



More information about the erlang-questions mailing list