[erlang-questions] Flush "stdout" buffer

PAILLEAU Eric eric.pailleau@REDACTED
Sat Sep 2 12:26:07 CEST 2017


Hi,

 From Erlang perspective, you can get the message queue length of io 
server handling your write.
io servers are erlang processes consuming an io messages queue.

To do so, you need to get the group leader pid of the writing process.

_______________________________________________
group_leader() -> pid()

Returns the process identifier of the group leader for the process 
evaluating the function.

Every process is a member of some process group and all groups have a 
group leader. All I/O from the group is channeled to the group leader. 
When a new process is spawned, it gets the same group leader as the 
spawning process. Initially, at system startup, init is both its own 
group leader and the group leader of all processes.
_______________________________________________

then you can ask the number of messages still in queue of group leader, 
using

  erlang:process_info/2 + message_queue_len


note that it is not however a guarantee that all data was flushed if 
message queue = 0, because last one message maybe currently being 
treated, and as other mentionned, you don't have control on what 
underlaying OS is doing low level.



>>
>> Hmmm ... So If i understand it well, we've no control on that after all.
>> The data can still be buffered on the kernel side.



More information about the erlang-questions mailing list