Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang finish or kill process

I have erlang application. In this application i run process with spawn(?MODULE, my_foo, [my_param1, my_param2, my_param3]).

And my_foo:

my_foo(my_param1, my_param2, my_param3) ->
  ...
  some code here
  ...
  ok.

When i open etop i see that this my_foo/3 function status: proc_lib:sync_wait/2

Than i try to put exit(self(), normal) in the end of my function, but i see same behavior: proc_lib:sync_wait/2 in etop.

How can i kill or exit process correctly?

Thank you.

like image 880
0xAX Avatar asked Jan 16 '12 09:01

0xAX


2 Answers

Note that exit(Pid, Reason) and exit(Reason) do NOT do the same thing if Pid is the process itself. exit/1 tells the current process to exit - from the inside if you like - while exit/2 sends an exit signal to the process, even if the process is itself. So when you do exit(self(), normal) you are actually sending the normal exit signal to yourself, which is ignored.

In this case putting the exit call at the end of the function should not make any difference as the process automatically dies (with reason normal) when the function with which it was started ends. It seems like the process is suspended somewhere before that.

proc_lib:sync_wait/2 is called inside proc_lib:start/start_link and sits and waits for the spawned process to do proc_lib:init_ack/1/2 to return the return value for start. It would appear that your process does not call init_ack.

like image 160
rvirding Avatar answered Oct 12 '22 14:10

rvirding


Based on the limited information that you give in the question I would suspect that your process hasn't finished running yet.

Normally you don't need to add exit/2 to your process. It will exit automatically when the function has finished running.

You probably have a long running call in some code here that has not finished running. I recommend that you add logging information and see where you are stuck.

like image 38
Daniel Luna Avatar answered Oct 12 '22 15:10

Daniel Luna