erlang

How do I found out which node an erlang process is running on?

喜你入骨 提交于 2019-12-08 15:20:43
问题 Given that I can send PIDs from a process to an other, even across nodes, if I receive a Pid from a process within a different process (possibly on a different node) how do I find out which node the PID in question runs in/on? erlang:process_info(Pid) does not seem to have that information in it. Thanks. 回答1: erlang:node/1 node(Arg) -> Node Returns the node where Arg is located. Arg can be a pid, a reference, or a port. If the local node is not alive, nonode@nohost is returned. 来源: https:/

Erlang/OTP How to notify parent process that child processes are idle and no messages in their mailbox

为君一笑 提交于 2019-12-08 14:00:01
问题 I would like to design a process hierarchy where there is a a parent process P which acts like a gatekeeper and delegates the work(messages/events from its client processes) to it's children processes C1,C2..Cn which collaborate with each other and may send the result back to P. The children processes cannot talk to any process outside, only P. The challenge is that though P may have multiple messages from its clients, it should accept only one message, delegate the work to C1..Cn and ONLY

How to load the resource file in Erlang

别等时光非礼了梦想. 提交于 2019-12-08 12:44:02
问题 What is a usual way of storing and loading resource file in Erlang. I need to create a certain human-readable dictionary and load it at application initialization. For example, in Java I would put the data in a .property file, then put it somewhere in the classpath and finally load it with help of code like this: new Properties().load(Class.getResourceAsStream("/file.properties")) So, I have the following questions: where I can (must) keep the resource file? how to determine in runtime the

inets httpc: client example in User's Guide not working

安稳与你 提交于 2019-12-08 10:43:31
问题 I copied the following code from the inets User's Guide: $ erl Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] Eshell V8.2 (abort with ^G) 1> inets:start(). ok 2> httpc:set_options([{proxy, {{"www-proxy.mycompany.com", 8000}, ["localhost"]}}]). ok 3> {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} = httpc:request("http://www.erlang.org"). * exception error: no match of right hand side value {error, {failed_connect, [{to_address,{"www

Debugging a function call that hangs in Erlang

孤街浪徒 提交于 2019-12-08 09:56:48
问题 It seems as if I have a caused a deadlock somewhere either in my code or in code that I'm using, but I am not sure how to debug it. Since I have no clue where the problem is and I can make the system almost completely idle, I think that it would be useful to see a trace of all functions and messages leading up to the hang. It looks like dbg provides some help in tracing, but I don't see how to configure it for such a broad trace. Is such a trace possible with dbg or are there other ways of

Erlang record expression ignored warning

夙愿已清 提交于 2019-12-08 09:10:42
I have following code: Check#tab_info{login_errors = 0}, {ok, PID}; But i get warning when i try to compile it: the result of the expression is ignored (suppress the warning by assigning the expression to the _ variable) What's wrong? How can i fix it? Thank you. Well, the compiler is telling you exactly what's wrong :) You create a new #tab_info record, but never bind it to any variable. The code is therefore meaningless and the compiler is telling you so. Changing the Check variable (or more correctly, creating a new one) won't have any effect unless you return it. Check is not a global

What is the correct use of process_flag(priority, Level) in Erlang?

纵然是瞬间 提交于 2019-12-08 08:30:19
问题 I want to use the process_flag(priority, Level) to set the priority of a process. I am a little confused as to where it should go in my code and can't seem to find an example. The two options that I can see are: (1) Set the flag before spawning the process: process_flag(priority, max), register(myprocess, spawn(fun() -> myprocess() end)), (2) Set the flag within the function after it has been spawned: myprocess() -> process_flag(priority, max), %do stuff Also, if option 1 is correct, do I

Erlang: what supervision tree should I end with writing a task scheduler?

巧了我就是萌 提交于 2019-12-08 07:06:55
问题 Mostly in educational purposes I'm trying to write a task (task is an open_port({spawn_executable, Command})) scheduler. I end up with the tree like supervisor | | scheduler receiver gen_event gen_event | supervisor | dispatcher gen_server | supervisor | | | task1 ... taskN In other words: top supervisor starts scheduler and receiver and makes sure they will be alive receiver starts middle supervisor middle supervisor starts dispatcher and makes sure it will be alive dispatcher starts bottom

CLOSED error when establishing lots of connections with gen_tcp in parallel (Bug?)

£可爱£侵袭症+ 提交于 2019-12-08 04:43:08
问题 When trying to establish a largeish number of TCP connections in parallel I observe some weird behavior I consider a potential bug in gen_tcp . The scenario is a server listening on a port with multiple concurrent acceptors. From a client I establish a connection by calling gen_tcp:connect/3 , afterwards I send a "Ping" message to the server and wait in passive mode for a "Pong" response. When performing the 'get_tcp:connect/3' calls sequentially all works fine, including for large number of

Time zone list issue

会有一股神秘感。 提交于 2019-12-08 03:53:12
问题 For my application, I'm importing the calendar event from google calendar. The only problem which I'm facing is Time zone list. I'm getting the timezone as output from google calendar xml, which I have to check with time zone list and add time accordingly... so from where I can get this standard time zone list.. or some other alternative to achieve the same. 回答1: If you're using Java, use Joda Time - the time zone ID given by Google Calendar will be one the Joda Time understands. The standard