如何手动将消息发送到我刚刚生成的进程? [英] How to manually send a message to a process which I just spawned?

查看:80
本文介绍了如何手动将消息发送到我刚刚生成的进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何发送消息以使用Erlang进行处理?我确实开始了一个过程,并且输出显示pid是< 0.39.0>. 我的问题是如何手动向此过程(< 0.39.0>)发送消息.

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 question is how can I send a message to this process (<0.39.0>) manually.

推荐答案

虽然确实可以使用list_to_pid/1构造PID,并建议不要使用它发送消息:

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

此BIF用于调试和在Erlang操作中使用 系统.不应在应用程序中使用它.

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

一种更好的方法是在开始该过程时保存PID:

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

这篇关于如何手动将消息发送到我刚刚生成的进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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