Start A process of another node

View: New views
7 Messages — Rating Filter:   Alert me  

Start A process of another node

by maruthavanan s :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

I need to start and stop a process on another node

Say for e.g I have a main node in erlang.

I have another sub node in erlang. I need to start some process in main node from sub node shell.

I achieved this by using the below

spawn('mainnode@TESTMACHINE',sample,start,[]).

but when I close the sub node the process is stopped. Is there any possibility that I can make the process live through out regardless of whether I close the sub node or not, the sample:start() would be running in main node?

Thanks,
Marutha
     

Re: Start A process of another node

by Jayson Vantuyl-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm unsure what to say here.  Erlang doesn't do this to me.

I started two nodes, one called main and one called sub.  I loaded the  
process manager on the main node.

I created a process on main using the following code:

> spawn(main@myhost,fun() -> receive {never,Never} -> ok after 30000 -
> > ok end end).


It stayed around even after exiting the original node.

That says to me that something that you process does depends on the  
original node.  A few questions about your code:

1.  Does it spawn_link(), spawn_opt() with the link option, or link()  
another process?
2.  Does it do I/O?
3.  Does it generate log messages?

The second two (I/O / log messages) use the "group leader", I  
believe.  In this case, the group leader would be on the original  
node, which might cause them to exit.  Generally, I believe the group  
leader of a process should be init.  To set the group leader to init  
on the new node, try:

> group_leader( whereis(init), self() )


Note that this will affect logging, supervision trees, and IO.  If you  
want to just start/stop a remotely supervised process, I recommend  
naming its supervisor globally, and adding/removing the childspec from  
the supervisor.

On Oct 26, 2009, at 11:19 PM, maruthavanan s wrote:

>
> Hi,
>
> I need to start and stop a process on another node
>
> Say for e.g I have a main node in erlang.
>
> I have another sub node in erlang. I need to start some process in  
> main node from sub node shell.
>
> I achieved this by using the below
>
> spawn('mainnode@TESTMACHINE',sample,start,[]).
>
> but when I close the sub node the process is stopped. Is there any  
> possibility that I can make the process live through out regardless  
> of whether I close the sub node or not, the sample:start() would be  
> running in main node?
>
> Thanks,
> Marutha
>  



--
Jayson Vantuyl
kagato@...






________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org


Re: Start A process of another node

by Michael Truog :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If you are using the slave module in the stdlib, since it tries to
cleanup zombie nodes. Since the process is not spawned with a link, it
shouldn't die. If your shell is attached to the node and you do abort
(after Ctrl-C), that could take it down. Instead you should do Ctrl-C twice.


maruthavanan s wrote:

> Hi,
>
> I need to start and stop a process on another node
>
> Say for e.g I have a main node in erlang.
>
> I have another sub node in erlang. I need to start some process in main node from sub node shell.
>
> I achieved this by using the below
>
> spawn('mainnode@TESTMACHINE',sample,start,[]).
>
> but when I close the sub node the process is stopped. Is there any possibility that I can make the process live through out regardless of whether I close the sub node or not, the sample:start() would be running in main node?
>
> Thanks,
> Marutha
>      
>  


________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org


RE: Start A process of another node

by maruthavanan s :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thanks for your support, I would like to elaborate what I am doing

I am using "Erlang (BEAM) emulator version 5.6.1 " with fedora core linux 9

I start one node of erlang as

 erl -sname main
(main@TESTMACHINE)1>

now I start  
 erl -sname sub
(sub@TESTMACHINE)1>

now I spawn from sub
spawn('mainnode@TESTMACHINE',sample,start,[]).

when I do erlang:registered() at main@TESTMACHINE
I can see the sample module registered at main node

when I try quit sub@TESTMACHINE
I can still see sample module registered at main node, but when I try to send message
using

erlang:send({'main@TESTMACHINE',sample},{"Message for Test"})

now the the registered module of sample vanishes at main node.

Please help me.

Below is the sample erlang code
-module(sample).
-compile(export_all).

start()->
register(sample,self()),
recv().

recv()->
receive
Msg->
        io:fwrite("Message Received ~p",[Msg])
end,
recv().

Thanks and regards,
Marutha

> CC: erlang-questions@...
> From: kagato@...
> To: maruthavanan_s@...
> Subject: Re: [erlang-questions] Start A process of another node
> Date: Tue, 27 Oct 2009 00:47:06 -0500
>
> I'm unsure what to say here.  Erlang doesn't do this to me.
>
> I started two nodes, one called main and one called sub.  I loaded the  
> process manager on the main node.
>
> I created a process on main using the following code:
>
> > spawn(main@myhost,fun() -> receive {never,Never} -> ok after 30000 -
> > > ok end end).
>
>
> It stayed around even after exiting the original node.
>
> That says to me that something that you process does depends on the  
> original node.  A few questions about your code:
>
> 1.  Does it spawn_link(), spawn_opt() with the link option, or link()  
> another process?
> 2.  Does it do I/O?
> 3.  Does it generate log messages?
>
> The second two (I/O / log messages) use the "group leader", I  
> believe.  In this case, the group leader would be on the original  
> node, which might cause them to exit.  Generally, I believe the group  
> leader of a process should be init.  To set the group leader to init  
> on the new node, try:
>
> > group_leader( whereis(init), self() )
>
>
> Note that this will affect logging, supervision trees, and IO.  If you  
> want to just start/stop a remotely supervised process, I recommend  
> naming its supervisor globally, and adding/removing the childspec from  
> the supervisor.
>
> On Oct 26, 2009, at 11:19 PM, maruthavanan s wrote:
>
> >
> > Hi,
> >
> > I need to start and stop a process on another node
> >
> > Say for e.g I have a main node in erlang.
> >
> > I have another sub node in erlang. I need to start some process in  
> > main node from sub node shell.
> >
> > I achieved this by using the below
> >
> > spawn('mainnode@TESTMACHINE',sample,start,[]).
> >
> > but when I close the sub node the process is stopped. Is there any  
> > possibility that I can make the process live through out regardless  
> > of whether I close the sub node or not, the sample:start() would be  
> > running in main node?
> >
> > Thanks,
> > Marutha
> >  
>
>
>
> --
> Jayson Vantuyl
> kagato@...
>
>
>
>
>
     

Re: Start A process of another node

by Mazen Harake-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

'main@TESTMACHINE' is not the same as 'mainnode@TESTMACHINE'...

maybe that is your problem.

Quoting the documentation for spawn/4:
"Returns the pid of a new process started by the application of Module:Function to Args on Node. If Node does not exists, a useless pid is returned. Otherwise works like spawn/3."

Hope this helps.

/Mazen
----- Original Message -----
From: "maruthavanan s" <maruthavanan_s@...>
To: kagato@...
Cc: erlang-questions@...
Sent: Tuesday, 27 October, 2009 09:58:05 (GMT+0200) Auto-Detected
Subject: RE: [erlang-questions] Start A process of another node


Thanks for your support, I would like to elaborate what I am doing

I am using "Erlang (BEAM) emulator version 5.6.1 " with fedora core linux 9

I start one node of erlang as

 erl -sname main
(main@TESTMACHINE)1>

now I start  
 erl -sname sub
(sub@TESTMACHINE)1>

now I spawn from sub
spawn('mainnode@TESTMACHINE',sample,start,[]).

when I do erlang:registered() at main@TESTMACHINE
I can see the sample module registered at main node

when I try quit sub@TESTMACHINE
I can still see sample module registered at main node, but when I try to send message
using

erlang:send({'main@TESTMACHINE',sample},{"Message for Test"})

now the the registered module of sample vanishes at main node.

Please help me.

Below is the sample erlang code
-module(sample).
-compile(export_all).

start()->
register(sample,self()),
recv().

recv()->
receive
Msg->
        io:fwrite("Message Received ~p",[Msg])
end,
recv().

Thanks and regards,
Marutha

> CC: erlang-questions@...
> From: kagato@...
> To: maruthavanan_s@...
> Subject: Re: [erlang-questions] Start A process of another node
> Date: Tue, 27 Oct 2009 00:47:06 -0500
>
> I'm unsure what to say here.  Erlang doesn't do this to me.
>
> I started two nodes, one called main and one called sub.  I loaded the  
> process manager on the main node.
>
> I created a process on main using the following code:
>
> > spawn(main@myhost,fun() -> receive {never,Never} -> ok after 30000 -
> > > ok end end).
>
>
> It stayed around even after exiting the original node.
>
> That says to me that something that you process does depends on the  
> original node.  A few questions about your code:
>
> 1.  Does it spawn_link(), spawn_opt() with the link option, or link()  
> another process?
> 2.  Does it do I/O?
> 3.  Does it generate log messages?
>
> The second two (I/O / log messages) use the "group leader", I  
> believe.  In this case, the group leader would be on the original  
> node, which might cause them to exit.  Generally, I believe the group  
> leader of a process should be init.  To set the group leader to init  
> on the new node, try:
>
> > group_leader( whereis(init), self() )
>
>
> Note that this will affect logging, supervision trees, and IO.  If you  
> want to just start/stop a remotely supervised process, I recommend  
> naming its supervisor globally, and adding/removing the childspec from  
> the supervisor.
>
> On Oct 26, 2009, at 11:19 PM, maruthavanan s wrote:
>
> >
> > Hi,
> >
> > I need to start and stop a process on another node
> >
> > Say for e.g I have a main node in erlang.
> >
> > I have another sub node in erlang. I need to start some process in  
> > main node from sub node shell.
> >
> > I achieved this by using the below
> >
> > spawn('mainnode@TESTMACHINE',sample,start,[]).
> >
> > but when I close the sub node the process is stopped. Is there any  
> > possibility that I can make the process live through out regardless  
> > of whether I close the sub node or not, the sample:start() would be  
> > running in main node?
> >
> > Thanks,
> > Marutha
> >  
>
>
>
> --
> Jayson Vantuyl
> kagato@...
>
>
>
>
>
     

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org


Re: Start A process of another node

by Jayson Vantuyl-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think the problem is the io:fwrite call.

I believe that IO goes through a process's "group leader", which is a  
sort of master process that handles things for groups of processes.

Since the group leader is no longer around (after sub exits), I bet  
that the process exits with an error. Since errors are logged through  
the group leader, you probably don't see an error either.

To fix this, after the process registers, change the group leader for  
your new process to the init process on the new node.

To do so, change your start function like this:

> start()->
> register(sample,self()),
> group_leader( whereis(init), self() ),
> recv().

Sent from my iPhone

On Oct 27, 2009, at 2:58 AM, maruthavanan s  
<maruthavanan_s@...> wrote:

>
> Thanks for your support, I would like to elaborate what I am doing
>
> I am using "Erlang (BEAM) emulator version 5.6.1 " with fedora core  
> linux 9
>
> I start one node of erlang as
>
> erl -sname main
> (main@TESTMACHINE)1>
>
> now I start
> erl -sname sub
> (sub@TESTMACHINE)1>
>
> now I spawn from sub
> spawn('mainnode@TESTMACHINE',sample,start,[]).
>
> when I do erlang:registered() at main@TESTMACHINE
> I can see the sample module registered at main node
>
> when I try quit sub@TESTMACHINE
> I can still see sample module registered at main node, but when I  
> try to send message
> using
>
> erlang:send({'main@TESTMACHINE',sample},{"Message for Test"})
>
> now the the registered module of sample vanishes at main node.
>
> Please help me.
>
> Below is the sample erlang code
> -module(sample).
> -compile(export_all).
>
> start()->
> register(sample,self()),
> recv().
>
> recv()->
> receive
> Msg->
>        io:fwrite("Message Received ~p",[Msg])
> end,
> recv().
>
> Thanks and regards,
> Marutha
>
>> CC: erlang-questions@...
>> From: kagato@...
>> To: maruthavanan_s@...
>> Subject: Re: [erlang-questions] Start A process of another node
>> Date: Tue, 27 Oct 2009 00:47:06 -0500
>>
>> I'm unsure what to say here.  Erlang doesn't do this to me.
>>
>> I started two nodes, one called main and one called sub.  I loaded  
>> the
>> process manager on the main node.
>>
>> I created a process on main using the following code:
>>
>>> spawn(main@myhost,fun() -> receive {never,Never} -> ok after 30000 -
>>>> ok end end).
>>
>>
>> It stayed around even after exiting the original node.
>>
>> That says to me that something that you process does depends on the
>> original node.  A few questions about your code:
>>
>> 1.  Does it spawn_link(), spawn_opt() with the link option, or link()
>> another process?
>> 2.  Does it do I/O?
>> 3.  Does it generate log messages?
>>
>> The second two (I/O / log messages) use the "group leader", I
>> believe.  In this case, the group leader would be on the original
>> node, which might cause them to exit.  Generally, I believe the group
>> leader of a process should be init.  To set the group leader to init
>> on the new node, try:
>>
>>> group_leader( whereis(init), self() )
>>
>>
>> Note that this will affect logging, supervision trees, and IO.  If  
>> you
>> want to just start/stop a remotely supervised process, I recommend
>> naming its supervisor globally, and adding/removing the childspec  
>> from
>> the supervisor.
>>
>> On Oct 26, 2009, at 11:19 PM, maruthavanan s wrote:
>>
>>>
>>> Hi,
>>>
>>> I need to start and stop a process on another node
>>>
>>> Say for e.g I have a main node in erlang.
>>>
>>> I have another sub node in erlang. I need to start some process in
>>> main node from sub node shell.
>>>
>>> I achieved this by using the below
>>>
>>> spawn('mainnode@TESTMACHINE',sample,start,[]).
>>>
>>> but when I close the sub node the process is stopped. Is there any
>>> possibility that I can make the process live through out regardless
>>> of whether I close the sub node or not, the sample:start() would be
>>> running in main node?
>>>
>>> Thanks,
>>> Marutha
>>>
>>
>>
>>
>> --
>> Jayson Vantuyl
>> kagato@...
>>
>>
>>
>>
>>
>

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org


Re: Start A process of another node

by Jayson Vantuyl-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Also, try using pman to monitor your processes. It's a bit nicer than  
watching for registered processes.

To start pman on a node, just run pman:start() in the shell on that  
node.

Sent from my iPhone

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org