Erlang Mailing Lists

Author Message

<  Erlang  ~  a null process?

yeejiun
Posted: Sun Sep 20, 2009 3:14 am Reply with quote
Joined: 20 Sep 2009 Posts: 2
Hi, I'm new to Erlang and have a quick question: is there such a thing as a null process in Erlang? i.e., is there a special Pid that I can send messages to such that those msgs will just get dropped?

I realize that it's easy to create such a process, but I'd like to know if a predefined one exists. Thanks.
View user's profile Send private message
Allan
Posted: Mon Sep 21, 2009 4:57 am Reply with quote
User Joined: 29 Jun 2009 Posts: 30
yeejiun wrote:
is there such a thing as a null process in Erlang? i.e., is there a special Pid that I can send messages to such that those msgs will just get dropped?

There is no predefined one.

Create a valid PID by calling "spawn(fun() -> ok end).". Then you can send messages to that PID without wasting memory or cycles due to message queueing because messages sent to terminated processes are dropped.
View user's profile Send private message Send e-mail ICQ Number
yeejiun
Posted: Mon Sep 21, 2009 5:19 am Reply with quote
Joined: 20 Sep 2009 Posts: 2
Thanks, Allan!
View user's profile Send private message
Mazen
Posted: Sun Sep 27, 2009 8:34 am Reply with quote
User Joined: 20 Jul 2006 Posts: 164 Location: London
Like:

Code:

Eshell V5.7.1  (abort with ^G)
1> NullPid = pid(0,0,0).
<0.0.0>
2> NullPid ! die.
die
3>

Very Happy
View user's profile Send private message
Allan
Posted: Sun Sep 27, 2009 2:05 pm Reply with quote
User Joined: 29 Jun 2009 Posts: 30
There is no BIF pid/3 outside the shell!

The documentation for c:pid/3 states: "This function should only be used when debugging.".
The documentation for list_to_pid/1 (that is used by c:pid/3) contains the warning "This BIF is intended for debugging and for use in the Erlang operating system. It should not be used in application programs.".

Rickard Green wrote in msg#00017 in lang.erlang.general: "Note that list_to_pid/1 and c:pid/3 are only intended to be used for debugging and testing. They should not be used in application programs."

Do not use the PID generation functions in production code.

P.S.: On my single node shell, PID <0.0.0> belongs to init:loop/1. Maybe sending it arbitrary messages is not a good idea... ;)
View user's profile Send private message Send e-mail ICQ Number
Mazen
Posted: Mon Sep 28, 2009 6:57 am Reply with quote
User Joined: 20 Jul 2006 Posts: 164 Location: London
Allan wrote:
There is no BIF pid/3 outside the shell!

The documentation for c:pid/3 states: "This function should only be used when debugging.".
The documentation for list_to_pid/1 (that is used by c:pid/3) contains the warning "This BIF is intended for debugging and for use in the Erlang operating system. It should not be used in application programs.".

Rickard Green wrote in msg#00017 in lang.erlang.general: "Note that list_to_pid/1 and c:pid/3 are only intended to be used for debugging and testing. They should not be used in application programs."

Do not use the PID generation functions in production code.

P.S.: On my single node shell, PID <0.0.0> belongs to init:loop/1. Maybe sending it arbitrary messages is not a good idea... Wink


Hehe, you are 100% right, I would also use what you suggested. But for the sake of my dignity you can also do this:
Code:
Eshell V5.7.1  (abort with ^G)
1> NullPid = pid(0,1,0).
<0.1.0>
2> NullPid ! die.
die
3>

For some reason pid 0.1.0 isn't used by anything, it is simply skipped. Probably it was used to bootstrap something or just do some initialization of something. Anyway, the concept is the same: Use a dead process' pid, thus using 0.1.0 has the same affect as what you proposed.

PS: Yes you would have to use the "BIF only intended for debugging"

phew Very Happy
View user's profile Send private message
rvirding
Posted: Wed Sep 30, 2009 6:16 pm Reply with quote
User Joined: 30 Aug 2006 Posts: 452 Location: Stockholm, Sweden
It's even worse than just using "debugging" BIFs. There is no guarantee that the pid of a dead process will not be reused in the future! Albeit it might take a long time and many spawns but eventually pids get reused.

Do you intend to send it big messages? If not then create a null process which just loops receive and throws away the messages. You could even register it as 'null'. Very Happy
View user's profile Send private message Visit poster's website MSN Messenger
wuji
Posted: Wed Aug 22, 2012 7:28 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
of unsuspecting malware-infected individuals without online access.What temporary Internet servers, servers, cheap jordans servers, you ask? They might have been connecting you to
YouTube, and -- ahem! -- ABCNews.com for the last month, month, cheap polo shirts month, and you didn't even know it. Really.Why is this
It all has to do with a piece of computer computer jordan 6s computer malware called DNS Changer.It started in 2007, when a
of hackers -- six Estonians and one Russian -- allegedly allegedly [h2]cheap replica *beep*[/h2] allegedly started masquerading as Internet advertisers who were paid by
click, according to an 2011 indictment from the U.S. Attorney Attorney cheap polo shirts Attorney General's Office in the Southern District of New York.
View user's profile Send private message
dongdongwu
Posted: Thu Sep 20, 2012 2:16 am Reply with quote
User Joined: 19 Sep 2012 Posts: 236
His good friend Diane said: "Christian Louboutin Men Shoes was a magician, he make shoes is immediately put his female people with legs and advantage. He understands women wanted to do and can make them into beautiful Cinderella." Madonna often in its concert wearing Christian louboutin high heels , and some famous superstar like Angelina jolie, mariah Carey, beyonce Knowles, the famous Japanese singer YaYouMei Hamasaki helps Christian Louboutin Men Shoes set up its powerful position. The youngest customers will count Tom cruise's daughter sully cruz. Louboutin made for only a pair of handmade Christian Louboutin high heel Shoes! Want to be more fashion? Put on Christian Louboutin Outlet !
Candy colors of the chalaza high-heeled shoes with lolita type allure, set full finely gem blue "neon shoes" is to need to use "sexy" to describe. Each pair are worth careful appreciation of lithe and graceful fairy ludaoli, what kind of most let you move?Christian Louboutin Men Shoes that one brush red is always cannot resist the temptation, Christian Louboutin men outlet continue to use the days of high 8cm above slender heel proclaim the sexy and luxuriant. The bowknot on black pointed high-heeled shoes with sharp rivet concomitant, wild python met enchanting color printing grain, It is that pairs of high-heeled shoes lets Carrie more feminine flavour. Like Christian Louboutin for men her word.
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum