Lua fork如何改写为支持长尾词并发进程的?

2026-04-01 19:421阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计485个文字,预计阅读时间需要2分钟。

Lua fork如何改写为支持长尾词并发进程的?

我想同时执行后台进程+喜爱:a=io.popen(deploy.exp, stdin=ip1):read(*a)b=io.popen(deploy.exp, stdin=ip2):read(*a)其中,a、b 是不断运行的进程。当我按下运行方式执行此操作时,b 仅在 a 完成后执行。

Lua fork如何改写为支持长尾词并发进程的?

我想从lua脚本同时执行后台进程

喜欢 :

a = io.popen("deploy.exp" .. ip1):read("*a") b = io.popen("deploy.exp" .. ip2):read("*a")

其中a,b是不断运行的进程.当我按上述方式执行此操作时,b仅在a完成时运行. deploy.exp脚本是一个期望脚本,用于ssh几个服务器,并执行一些命令.然后我需要从a和b中获取一些文本.有什么想法吗?我尝试使用ExtensionProposal API.当我尝试时,我得到一条错误消息,说:“* glibc检测到free():无效的下一个大小(快):0x08aa2300 ** abort”.

零件代码是

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

有没有人有任何经验(或建议/我们应该在哪里看)?或者给我一个样品?谢谢

BTW:我尝试过luaposix,但我找不到posix.fork()的任何样本.有人可以分享吗? TKS

posix.fork()是 luaposix library的一部分,可以通过 luarocks安装.它的工作方式与 fork(3)大致相同.它创建父进程的副本,并且在调用fork()之后它们都将执行所有内容. fork()的返回值在子进程中为0,否则它是刚刚生成的子进程的PID.这是一个人为的例子:

local posix = require "posix" local pid = posix.fork() if pid == 0 then -- this is the child process print(posix.getpid('pid') .. ": child process") else -- this is the parent process print(posix.getpid('pid') .. ": parent process") -- wait for the child process to finish posix.wait(pid) end -- both processes get here print(posix.getpid('pid') .. ": quitting")

这应该输出如下内容:

$lua fork.lua 27219: parent process 27220: child process 27220: quitting 27219: quitting

本文共计485个文字,预计阅读时间需要2分钟。

Lua fork如何改写为支持长尾词并发进程的?

我想同时执行后台进程+喜爱:a=io.popen(deploy.exp, stdin=ip1):read(*a)b=io.popen(deploy.exp, stdin=ip2):read(*a)其中,a、b 是不断运行的进程。当我按下运行方式执行此操作时,b 仅在 a 完成后执行。

Lua fork如何改写为支持长尾词并发进程的?

我想从lua脚本同时执行后台进程

喜欢 :

a = io.popen("deploy.exp" .. ip1):read("*a") b = io.popen("deploy.exp" .. ip2):read("*a")

其中a,b是不断运行的进程.当我按上述方式执行此操作时,b仅在a完成时运行. deploy.exp脚本是一个期望脚本,用于ssh几个服务器,并执行一些命令.然后我需要从a和b中获取一些文本.有什么想法吗?我尝试使用ExtensionProposal API.当我尝试时,我得到一条错误消息,说:“* glibc检测到free():无效的下一个大小(快):0x08aa2300 ** abort”.

零件代码是

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

有没有人有任何经验(或建议/我们应该在哪里看)?或者给我一个样品?谢谢

BTW:我尝试过luaposix,但我找不到posix.fork()的任何样本.有人可以分享吗? TKS

posix.fork()是 luaposix library的一部分,可以通过 luarocks安装.它的工作方式与 fork(3)大致相同.它创建父进程的副本,并且在调用fork()之后它们都将执行所有内容. fork()的返回值在子进程中为0,否则它是刚刚生成的子进程的PID.这是一个人为的例子:

local posix = require "posix" local pid = posix.fork() if pid == 0 then -- this is the child process print(posix.getpid('pid') .. ": child process") else -- this is the parent process print(posix.getpid('pid') .. ": parent process") -- wait for the child process to finish posix.wait(pid) end -- both processes get here print(posix.getpid('pid') .. ": quitting")

这应该输出如下内容:

$lua fork.lua 27219: parent process 27220: child process 27220: quitting 27219: quitting