Open shaleengarg opened 8 years ago
Hi @shaleengarg, do you know what number that exercise is? It looks like there are at least 6 exercises for chapter 13, and I have only completed 4 in this repository. If you let me know what number that exercise was I'll try to add that it as well.
Hi @Stratus3D . Its question 5 and 6 (Pg 209)
Hi @Stratus3D Please take a look at this code
%%Coded By shaleengarg %%This module generates N processes on node and kills them -module(processes). -export([wait/0, master/1, sp/1]).
sp(N) -> Max = erlang:system_info(process_limit), io:format("Maximum allowed processes:~p~n",[Max]), statistics(runtime), statistics(wallclock), L = for(1, N, fun() -> spawn(fun() -> wait() end) end), {, Time1} = statistics(runtime), {_, Time2} = statistics(wall_clock), lists:foreach(fun(Pid) -> Pid ! die end, L), U1 = Time1 * 1000 / N, U2 = Time2 * 1000 / N, io:format("Process spawn time=~p (~p) microseconds from node: ~p ~n", [U1, U2, node()]).
%%list of the form [{Number of processes, Node}...] master([]) -> [];
master(List) -> [H|T] = List, {Number, Node} = H, subordinate(Number, Node), io:format("Spawned a subordinate~n"), master(T).
subordinate(Number, Node) -> spawn(Node, ?MODULE, sp, [Number]).
wait() -> receive die -> void end.
for(N, N, F) -> [F()]; for(I, N, F) -> [F()| for(I+1, N, F)].
I wrote this code myself. Please review this code. I will be happy to issue a push request
Sorry it's taken me so long to respond. I'm in the process of updating everything for Chapter 13. I'm working on adding more detailed comments to all the exercises. Last night I pushed the solution for exercise 13.4. Hoping to push the solution for 13.5 sometime this week.
In all your README.md
files you need to leave a space after the ###
marks for them to create headings:
###MyHeading
v.
### MyHeading
This is how it's rendered:
MyHeading
v.
MyHeading
@7stud thanks. I've fixed the formatting of all the README files.
In chapter 13, there is a question which asks us to write a program which can monitor multiple processes(workers). I have written a program which can monitor one process, but am not sure how to scale that for multiple processes.