Q: Supervision and Magically Reincarnated Processes

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Q: Supervision and Magically Reincarnated Processes

Bruce Fitzsimons-2
Hi peoples,

A quick OTP question, I'm using supervisors in my Aplio (Internet Phone)
server program and I've carefully inserted a bug somewhere that makes one of
the processes crash. But I don't get any output about why it has crashed in
the error_logger or shell (when I run it that way).

The process that dies is a gen_server (behaviour) and it doesn't execute its
terminate(Reason, State) so I guess its just 'EXIT'ing somewhere.

My question is: how can I trap this (preferably sans debugger)?

The supervisor restarts it happily, and works so fast and well that I wasn't
even aware it was dying until I started running it in the shell this week.

/Bruce




Reply | Threaded
Open this post in threaded view
|

Q: Supervision and Magically Reincarnated Processes

Ulf Wiger-4
On Mon, 16 Dec 2002, Bruce Fitzsimons wrote:

>The process that dies is a gen_server (behaviour) and it
>doesn't execute its terminate(Reason, State) so I guess its
>just 'EXIT'ing somewhere.

One comment: if the process doesn't trap exits and is linked
to some process that dies, the terminate/2 function will not
be executed.

/Uffe
--
Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson Telecom AB, ATM Multiservice Networks



Reply | Threaded
Open this post in threaded view
|

Q: Supervision and Magically Reincarnated Processes

Vance Shipley-2
In reply to this post by Bruce Fitzsimons-2
Bruce,

You need to do the following in your init/1 function:

        process_flag(trap_exit, true)

Normally the {'EXIT', Pid, Reason} message is handled for you but after
setting this you will receive it in your handle_info/2 call back.  You
can do cleanup/reporting and return {stop,Reason,NewState}.  Now terminate/2
will be called.  Afterwards the supervisor will start it up again.

        -Vance

On Mon, Dec 16, 2002 at 09:18:14PM +1300, Bruce Fitzsimons wrote:
}  
}  The process that dies is a gen_server (behaviour) and it doesn't execute its
}  terminate(Reason, State) so I guess its just 'EXIT'ing somewhere.
}  
}  My question is: how can I trap this (preferably sans debugger)?


Reply | Threaded
Open this post in threaded view
|

Process alive ?

Michał Ptaszek

Does anyone know how can I check if a process running in a node is alive ?

Thanks,
Bernardo Paroli
INSwitch Solutions





Reply | Threaded
Open this post in threaded view
|

Process alive ?

Vance Shipley-2

You can use erlang:process_info/1.

1> Pid = self().
<0.25.0>
2> process_info(Pid).
[{current_function,{erl_eval,expr,3}},
 {initial_call,{shell,evaluator,3}},
 {status,running},
 {message_queue_len,0},
 {messages,[]},
 {links,[<0.22.0>]},
 {dictionary,[]},
 {trap_exit,false},
 {error_handler,error_handler},
 {priority,normal},
 {group_leader,<0.21.0>},
 {heap_size,233},
 {stack_size,13},
 {reductions,89},
 {garbage_collection,[{fullsweep_after,65535}]}]
3> banf = bang.
** exited: {{badmatch,bang},[{erl_eval,expr,3}]} **
4> self().
<0.34.0>
5> process_info(Pid).
undefined

On Tue, Dec 17, 2002 at 08:40:27PM +0100, Inswitch Solutions - Erlang Evaluation wrote:
}  
}  Does anyone know how can I check if a process running in a node is alive ?
}  
}  Thanks,
}  Bernardo Paroli
}  INSwitch Solutions
}  
}  
}  


Reply | Threaded
Open this post in threaded view
|

Process alive ?

Vladimir Sekissov
In reply to this post by Michał Ptaszek
Good day,

You can use

is_process_alive(Pid)

or

rpc:call(Node, erlang, is_process_alive, [Pid])

if it is on another node.

Best Regards,
Vladimir Sekissov

erlang>
erlang> Does anyone know how can I check if a process running in a node is alive ?
erlang>
erlang> Thanks,
erlang> Bernardo Paroli
erlang> INSwitch Solutions
erlang>
erlang>


Reply | Threaded
Open this post in threaded view
|

Process alive ?

Michał Ptaszek
In reply to this post by Vance Shipley-2
Ok, but I don't know the Pid of the process. For example I have a process
running in a node e1 and another process running in a node
e2, from node e1 I need send a message to application running in e2
node, in node e1 I write the next code
{application, e2} ! {self(),  "Message to send"},
receive
    {ok, Reply} ->
          .....
end

But if the application it's not running in the e2 node I don't receive any
error.


----- Original Message -----
From: "Vance Shipley" <vances>
To: "Inswitch Solutions - Erlang Evaluation" <erlang>
Cc: <erlang-questions>
Sent: Monday, December 16, 2002 8:56 PM
Subject: Re: Process alive ?


>
> You can use erlang:process_info/1.
>
> 1> Pid = self().
> <0.25.0>
> 2> process_info(Pid).
> [{current_function,{erl_eval,expr,3}},
>  {initial_call,{shell,evaluator,3}},
>  {status,running},
>  {message_queue_len,0},
>  {messages,[]},
>  {links,[<0.22.0>]},
>  {dictionary,[]},
>  {trap_exit,false},
>  {error_handler,error_handler},
>  {priority,normal},
>  {group_leader,<0.21.0>},
>  {heap_size,233},
>  {stack_size,13},
>  {reductions,89},
>  {garbage_collection,[{fullsweep_after,65535}]}]
> 3> banf = bang.
> ** exited: {{badmatch,bang},[{erl_eval,expr,3}]} **
> 4> self().
> <0.34.0>
> 5> process_info(Pid).
> undefined
>
> On Tue, Dec 17, 2002 at 08:40:27PM +0100, Inswitch Solutions - Erlang
Evaluation wrote:
> }
> }  Does anyone know how can I check if a process running in a node is
alive ?
> }
> }  Thanks,
> }  Bernardo Paroli
> }  INSwitch Solutions
> }
> }
> }
>



Reply | Threaded
Open this post in threaded view
|

Process alive ?

Ulf Wiger-4
In reply to this post by Vladimir Sekissov
On Tue, 17 Dec 2002, Vladimir Sekissov wrote:

>Good day,
>
>You can use
>
>is_process_alive(Pid)
>
>or
>
>rpc:call(Node, erlang, is_process_alive, [Pid])
>
>if it is on another node.


Or, if you don't have a Pid,

 whereis(LogicalName)

assuming that the process has registered a logical name
using register(LogicalName, self()).

whereis/1 returns a pid or 'undefined'.

If you're checking from a remote node:

  rpc:call(Node, erlang, whereis, [LogicalName]).

You can also use erlang:monitor(process, PidOrName).
If the process is not alive, you will receive a 'DOWN'
message. This is what gen:call() does. It works also in a
distributed setting.


/Uffe
--
Ulf Wiger, Senior Specialist,
   / / /   Architecture & Design of Carrier-Class Software
  / / /    Strategic Product & System Management
 / / /     Ericsson Telecom AB, ATM Multiservice Networks



Reply | Threaded
Open this post in threaded view
|

Process alive ?

Martin Carlson-2
In reply to this post by Michał Ptaszek
If the process is registered then you can do a whereis/1 if it is not
then you must have some way of identifying it i.e pid(). If you have its
pid() then you can interact with it in any number of ways. The cleanest
is is_process_alive(Pid) the Pid argument must refer to a process of the
same node as the call. Things of this sort can usually be found in the
kernel module "erlang".

Cheers,
Martin

On Tue, 2002-12-17 at 13:40, Inswitch Solutions - Erlang Evaluation
wrote:
>
> Does anyone know how can I check if a process running in a node is alive ?
>
> Thanks,
> Bernardo Paroli
> INSwitch Solutions
>
>
>