@@ -18,7 +18,7 @@ Solution in [exercise_4/](exercise_4).
18
18
19
19
** 5. Write a function that spawns and monitors several processes. If any monitored processes dies, restart the monitored process.**
20
20
21
- Solution in [ exercise_5/] ( exercise_5 ) . The code is in ` workers .erl`
21
+ Solution in [ exercise_5/] ( exercise_5 ) . The code is in ` worker_supervisor .erl`
22
22
23
23
Example usage:
24
24
@@ -36,9 +36,24 @@ I'm still running
36
36
3> [{Pid, _, _, _}|_] = WorkerData.
37
37
% And kill it to verify it got restarted
38
38
4> exit(Pid, test).
39
- 1> workers:spawn_and_restart_workers(workers:definition()).
40
39
```
41
40
42
41
** 6. Write a function that spawns and monitors several processes. If any monitored processes dies, kill all the processes and restart them.**
43
42
44
- Solution in [ exercise_6/] ( exercise_6 ) .
43
+ Solution in [ exercise_6/] ( exercise_6 ) . The code is in ` worker_supervisor.erl `
44
+
45
+ ```
46
+ erlc worker_supervisors.erl
47
+ erl
48
+ % Start the supervisor with a list of children
49
+ 1> SupervisorPid = worker_supervisor:start(worker_supervisor:definition()).
50
+ I'm still running
51
+ I'm still running
52
+ % Get one of the child processes
53
+ 2> WorkerData = worker_supervisor:get_workers(SupervisorPid).
54
+ [{<0.41.0>,#Ref<0.0.4.148>,-576460742360537501,{worker_supervisor,test,[]}},
55
+ {<0.42.0>,#Ref<0.0.4.149>,-576460742360529319,{worker_supervisor,test,[]}}]
56
+ 3> [{Pid, _, _, _}|_] = WorkerData.
57
+ % And kill it to verify it got restarted
58
+ 4> exit(Pid, test).
59
+ ```
0 commit comments