发送消息Pid Erlang [英] Sending message Pid Erlang

查看:209
本文介绍了发送消息Pid Erlang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,我如何发送一个消息来处理与erlang。
我确实启动了一个进程,输出显示pid为< 0.39.0>。
我的问题是如何手动发送一个消息到这个过程(<0.39.0>)。



Anyhelp将不胜感激

解决方案

虽然 list_to_pid / 1 确实可以用来构造PID并使用它发送不鼓励使用它的用法:


此BIF旨在用于Erlang运行
系统的调试和使用。不应该在应用程序中使用。


更好的方法是在启动过程时保存PID:

  1> P = spawn(fun() - > receive _  - > ok end end)。 
< 0.34.0>
2> P!喜。
hi


I would like to know, how can i send a message to process with erlang. I did start a process and the output shows me that the pid is <0.39.0>. My problem is how can i send a message to this process (<0.39.0>) manually.

Anyhelp would be appreciated

解决方案

While list_to_pid/1 can indeed be used to construct a PID and use it to send messages its usage is discouraged:

This BIF is intended for debugging and for use in the Erlang operating system. It should not be used in application programs.

A better approach would be to save the PID when you start the process:

1> P = spawn(fun() -> receive _ -> ok end end).
<0.34.0>
2> P!hi.
hi

这篇关于发送消息Pid Erlang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆