Console ouput

Lennart Öhman lennart.ohman@REDACTED
Wed Oct 8 20:07:56 CEST 2003

Read the code of io.erl in stdlib and you will understand.

request(standard_io, Request) ->
     request(group_leader(), Request);
request(Pid, Request) when pid(Pid) ->
     Mref = erlang:monitor(process,Pid),
     Pid ! {io_request,self(),Pid,io_request(Request)},
request(Name, Request) when atom(Name) ->
     case whereis(Name) of
	undefined ->
	    {error, arguments};
	Pid ->
	    request(Pid, Request)

Group leader is actully one of the few things which are inherited
in Erlang - from parent to spawned process.
In the IO context the group leader is simply used to identify who
handles standard_io for that process. You see that in the code above.
For instance calling io:format/2 causes a io_request message to
be sent to the process acting as its group-leader.

If you wish to send io to another particular process, just simply
use IO functions with a descriptor argument. By studying the io code
(as above) you see what messages to expect in the receiving process.


Inswitch Solutions - Erlang Evaluation wrote:

> If process P executes group_leader(GP, self(), all console ouput will be 
> sent to process GP?
> If not, how can I send all console ouput of a process to another process.
> Thanks,
> Eduardo Figoli
> INSwitch Solutions

Lennart Ohman                   phone   : +46-8-587 623 27
Sjoland & Thyselius Telecom AB  cellular: +46-70-552 6735
Sehlstedtsgatan 6               fax     : +46-8-667 8230
SE-115 28 STOCKHOLM, SWEDEN     email   : lennart.ohman@REDACTED

More information about the erlang-questions mailing list