<div>Ok, thanks for the clarification.</div><div dir="auto"><br></div><div dir="auto">/Frank</div><div><br><div class="gmail_quote"><div>Le sam. 2 sept. 2017 à 19:15, Michael Truog <<a href="mailto:mjtruog@gmail.com">mjtruog@gmail.com</a>> a wrote :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 09/02/2017 04:08 AM, Per Hedeland wrote:<br>
> On 2017-09-02 10:07, Michael Truog wrote:<br>
>> On 09/01/2017 04:58 AM, Frank Muller wrote:<br>
>>> Can someone help on this please?<br>
>>><br>
>> If you use stdout as an Erlang port like:<br>
>><br>
>> STDOUT = erlang:open_port({fd, 0, 1}, [out, {line, 256}]),<br>
>> erlang:port_command(STDOUT, "unbuffered").<br>
><br>
> Can you actually observe a difference *in buffering* between doing that<br>
> and just<br>
><br>
> io:format("unbuffered").<br>
<br>
Yes, it really does matter. You will notice that the io module doesn't have any flush function, so you are unable to force any buffering in the Erlang VM to flush. However, if you really care about stdout in unbuffered mode, you need to use the Erlang port as described above. That is similar to using fcntl to set file descriptor 1 with O_NONBLOCK. Programming languages normally have a way of setting stdout (and stderr, though stderr is really suppose to always be in unbuffered mode) in an unbuffered mode so all the output is available as quickly as possible. An example for C++ is:<br>
<br>
setbuf(stdout, NULL);<br>
std::cout.setf(std::ios::unitbuf);<br>
<br>
If you have pipes setup to handle stdout/stderr from a forked OS process that is executing a programming language, you want to have stdout and stderr in unbuffered mode to ensure the output is available without any extra delays (e.g., for logging). Otherwise, it is problematic if the OS process crashes, because you may never receive a stacktrace (if one is provided) or any other output if it is available.<br>
<br>
That is why each external (running in an OS process, not in the Erlang VM) CloudI API implementation (<a href="https://github.com/CloudI/CloudI/tree/develop/src/api" rel="noreferrer" target="_blank">https://github.com/CloudI/CloudI/tree/develop/src/api</a>) puts stdout and stderr into unbuffered mode. In Erlang source code we can't really put the io server into an unbuffered mode, and there is no reason to really, because it is simpler to bypass the io server by making an Erlang port, as shown above.<br>
<br>
Best Regards,<br>
Michael<br>
</blockquote></div></div>