I want to execute background processes concurrently from a lua script
like :
a = io.popen("deploy.exp" .. ip1):read("*a")
b = io.popen("deploy.exp" .. ip2):read("*a")
where a,b are continually running processes. When i do this as above, b will only run when a is finished. And the deploy.exp script is an expect script which used to ssh few servers, and execute some commands. Then I need to fetch some text from a and b. Any idea on this? I tryed with the ExtensionProposal API. When I tried that I get one error messages that say: “* glibc detected free(): invalid next size (fast): 0x08aa2300 ** abort”.
The part code is
for k,v in pairs(single) do
command = k .. " 1 " .. table.concat(v, " ")
local out = io.pipe()
local pro = assert(os.spawn("./spaw.exp " .. command,{
stdout = out,
}))
if not proc then error("Failed to aprogrinate! "..tostring(err)) end
print(string.rep("#", 50))
local exitcode = proc:wait()
end
Has anybody any experience (or advice / where we should look) with this? or give me a sample? Thanks
BTW: I tried the luaposix, but I can’t find any sample by posix.fork(). Does anyone could share one? TKS
posix.fork() is part of the luaposix library, which can be installed via luarocks. It works in much the same way as fork(3); it creates an copy of the parent process, and both of them will execute everything after the call to fork(). The return value of fork() is 0 in the child process, otherwise it’s the PID of the child that was just spawned. Here’s a contrived example:
This should output something like the following: