Erlang/OTP Forums

Author Message

<  Erlang questions mailing list  ~  Where does io:format's output go? Or where SHOULD it go?

Guest
Posted: Fri Apr 25, 2008 6:48 am Reply with quote
Guest
Excuse me if this is a dim question; although I am a fan of Erlang, my
experience is limited: I teach at a college and this will be only the
second time I've introduced the language (and the FP paradigm) into our
Network Programming course.

While setting up a demo for my students to show them how simple it is to
load code into another Erlang node and to start processes in another
node, when I do this - I start a shell on two systems in two windows,
load code from one node to the other and start it - it doesn't matter
whether I start the process on the second node via spawn/4 or
rpc:call/4, the output, written via io:format by the process on the
second node always appears on the first node.

Is this a feature of the shell?

And a related question: when I run the shell with the -detached flag and
start a process via -eval where does the io:format output go then?

--

Deryk Barker, Computer Science Dept. Music does not have to be
understood
Camosun College, Victoria, BC, Canada It has to be listened to.
email: dbarker@camosun.bc.ca
phone: +1 250 370 4452 Hermann
Scherchen.


_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
Guest
Posted: Fri Apr 25, 2008 7:29 am Reply with quote
Guest
Deryk Barker wrote:
> While setting up a demo for my students to show them how simple it is to
> load code into another Erlang node and to start processes in another
> node, when I do this - I start a shell on two systems in two windows,
> load code from one node to the other and start it - it doesn't matter
> whether I start the process on the second node via spawn/4 or
> rpc:call/4, the output, written via io:format by the process on the
> second node always appears on the first node.
>
> Is this a feature of the shell?

Not the of shell, but of the IO system as a whole. Every Erlang process
has an associated "group leader" process, that represents the standard-IO
output and input. The group leader is inherited, so new processes get the
same standard output as their parent (this is generally what you want),
but it can be reassigned. So even though your new processes are spawned
on a remote node, their standard IO is still sent to the original group
leader on the initial node (a great example of transparency, actually).

You could make a neat demonstration by letting the remote process read a
local file (i.e. on the remote node) and print the contents on stdout,
which will then show up on the caller's terminal. To show some activity
on the remote node, you can explicitly write to 'user' instead of stdout,
as in `io:fwrite(user,"the result is ~w\n",[X])'.

/Richard


_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
Guest
Posted: Fri Apr 25, 2008 7:51 am Reply with quote
Guest
On Thu, Apr 24, 2008 at 08:37:37PM -0700, Deryk Barker wrote:
> Excuse me if this is a dim question; although I am a fan of Erlang, my
> experience is limited: I teach at a college and this will be only the
> second time I've introduced the language (and the FP paradigm) into our
> Network Programming course.
>
> While setting up a demo for my students to show them how simple it is to
> load code into another Erlang node and to start processes in another
> node, when I do this - I start a shell on two systems in two windows,
> load code from one node to the other and start it - it doesn't matter
> whether I start the process on the second node via spawn/4 or
> rpc:call/4, the output, written via io:format by the process on the
> second node always appears on the first node.
>
> Is this a feature of the shell?

Not really.

Every erlang process has a "group leader", and that is a process that
io:format/2,3 per default use as IO server for output.

Check out erlang:group_leader/0,1.

spawn/4 makes the spawned process inherit the parent's group leader.

rpc:call/4 passes the caller's group leader to the RPC server,
and the RPC server sets the group leader of spawned process that
executes the RPC call.

And since it does not matter much if a process is
local or remote remote it works just fine with a remote
group leader.

If you instead call erlang:display/1 via RPC you will see
the argument is displayed on the executing node's terminal.

>
> And a related question: when I run the shell with the -detached flag and
> start a process via -eval where does the io:format output go then?
>

The erlang node detaches from its terminal and all io:format
output (that goes to the default group leader (that prints
on STDOUT)) goes to /dev/null.

> --
>
> Deryk Barker, Computer Science Dept. Music does not have to be
> understood
> Camosun College, Victoria, BC, Canada It has to be listened to.
> email: dbarker@camosun.bc.ca
> phone: +1 250 370 4452 Hermann
> Scherchen.
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@erlang.org
> http://www.erlang.org/mailman/listinfo/erlang-questions

--

/ Raimo Niskanen, Erlang/OTP, Ericsson AB
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum