问题
(nodeA@foo.hyd.com)8> spawn(nodeA@bar.del.com, tut, test, [hello, 5]).
I want to spawn a process on bar.del.com which has no file system access to foo.hyd.com (from where I am spawning the process), running subroutine "test" of module "tut".
Is there a way to do so, w/o providing the nodeA@bar.del.com with the compiled "tut" module file?
回答1:
You can use the following function to load a module at remote node without providing the file itself:
load_module(Node, Module) ->
{_Module, Bin, Filename} = code:get_object_code(Module),
rpc:call(Node, code, load_binary, [Module, Filename, Bin]).
As noted in code:load_binary/3
Filename
argument is used only to track the path to module and the file it points to is not used by local node_server.
回答2:
I'm interpreting your question as a desire to not copy the *.beams from your filesystem to the remote file system.
If you are just testing things you can use the nl(Mod)
call in the erl shell to load the module on all (currently) known nodes. That is, those that show up in nodes()
.
This will send the code over and load it from the memory copy, it will not store it in the remote filesystem.
You can also start the remote node using the slave
module. A slave accesses its master's filesystem and code server. Ordinary auto-loading will then make sure the module exists in the slave when you call your test:tut/2
function.
回答3:
You can send the local code to the remote node:
> {Mod, Bin, File} = code:get_object_code(Module).
> rpc:call(RemoteNode, code, load_binary, [Mod, File, Bin]).
来源:https://stackoverflow.com/questions/1945899/spawn-remote-process-w-o-common-file-system