gpt4 book ai didi

elixir - 什么是组长

转载 作者:行者123 更新时间:2023-12-04 11:03:12 25 4
gpt4 key购买 nike

我正在尝试配置,什么是组长以及它与 I/O 模块的关系,但在互联网上找不到任何有用的东西。可以请人解释一下吗?
我有以下来自 elixir 1.2 book(Dave Thomas) 的场景:
enter image description here
在第二个窗口,他为什么通过:erlang_group_leader ?它有什么用?

最佳答案

From documentation :

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 start-up, init is both its own group leader and the group leader of all processes.


和:
group_leader(GroupLeader, Pid) -> true

Types:

GroupLeader = Pid = pid()

Sets the group leader of Pid to GroupLeader. Typically, this is used when a process started from a certain shell is to have another group leader than init.

See also group_leader/0.

还有一些 Elixir-specific documentation :

By modelling IO devices with processes, the Erlang VM allows different nodes in the same network to exchange file processes in order to read/write files in between nodes. Of all IO devices, there is one that is special to each process: the group leader.

The group leader can be configured per process and is used in different situations. For example, when executing code in a remote terminal, it guarantees messages in a remote node are redirected and printed in the terminal that triggered the request.

关于elixir - 什么是组长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36318766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com