From b0900fc2f7daab1c77dd8878c39ab24591bb076b Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Thu, 5 Apr 2018 01:40:20 +0200 Subject: Explain why the AM becomes group leader --- lib/kernel/doc/src/application.xml | 10 +++++++--- lib/kernel/src/application_master.erl | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/kernel') diff --git a/lib/kernel/doc/src/application.xml b/lib/kernel/doc/src/application.xml index 886286b76d..be914aee87 100644 --- a/lib/kernel/doc/src/application.xml +++ b/lib/kernel/doc/src/application.xml @@ -318,8 +318,13 @@ Nodes = [cp1@cave, {cp2@cave, cp3@cave}] {error,{not_started,App}} is returned, where App is the name of the missing application.

The application controller then creates an application master - for the application. The application master is - the group leader of all the processes in the application. + for the application. The application master becomes the + group leader of all the processes in the application. I/O is + forwarded to the previous group leader, though, this is just + a way to identify processes that belong to the application. + Used for example to find itself from any process, or, + reciprocally, to kill them all when it terminates.

+

The application master starts the application by calling the application callback function Module:start/2 as defined by the application specification key mod.

@@ -608,4 +613,3 @@ Nodes = [cp1@cave, {cp2@cave, cp3@cave}] app(4)

- diff --git a/lib/kernel/src/application_master.erl b/lib/kernel/src/application_master.erl index 5da2b0b06c..06991b45e1 100644 --- a/lib/kernel/src/application_master.erl +++ b/lib/kernel/src/application_master.erl @@ -118,6 +118,10 @@ init(Parent, Starter, ApplData, Type) -> link(Parent), process_flag(trap_exit, true), OldGleader = group_leader(), + %% We become the group leader, but forward all I/O to OldGleader. + %% This is just a way to identify processes that belong to the + %% application. Used for example to find ourselves from any + %% process, or, reciprocally, to kill them all when we terminate. group_leader(self(), self()), %% Insert ourselves as master for the process. This ensures that %% the processes in the application can use get_env/1 at startup. -- cgit v1.2.3