Guard test pid/1 allows invalid Pid into spawned program

Vlad Dumitrescu <>
Thu Dec 16 09:20:15 CET 2004


Yes, links work even for remote processes. And no, processes are not garbage
collected, they live until the function they were spawned with ends.

Usually, if one uses spawn (as opposed to spawn_link) there is no link created
between processes, and thus the spawned process doesn't depend on the parent
remaining alive. The link can be severed, but it's bad programming practice, as
the place (process) that opened the file should also close it (otherwise the
file process could keep running for all eternity)

I'd suggest another approach: the process that opens LogStream should be a
server that can hand out the pid to clients and also receives 'close' commands
from them.

Better, the owner process can be made a logging server and send it's own pid ti
the children: the children just say 'write this data to the log', without caring
whether if the log medium is a file or a database or something else.

I hope this helps. The documentation and the book contain more detailed
information, but please ask again if it's not clear enough.


----- Original Message ----- 
From: "Roger Price" <>
To: "Erlang mailing list" <>
Sent: Wednesday, December 15, 2004 10:49 PM
Subject: Re: Guard test pid/1 allows invalid Pid into spawned program

> Thanks for the insight.  I was under the mistaken impression that somehow
> processes, like memory, were garbage collected only when the "last
> pointer" disappeared.
> Does the link-based garbage collection work between nodes?  I.e, if I pass
> a Pid to my hello/1 in another node must I keep test/0 alive in the
> originating node to keep the "LogStream" Pid alive on some distant node?
> Best Regards,
> Roger

More information about the erlang-questions mailing list