local posix = require("posix_c")
local function _process()
local pid, err = posix.fork()
if err then
end
if 0 ~= pid then
ngx.log(ngx.INFO, 'hello pid : ', pid)
return {
key = 'hello'
}
else
os.execute("sleep 5")
os.exit()
end
end
local result = {}
if ngx.ctx.method == 'POST' then
elseif ngx.ctx.method == 'GET' then
result = _process()
-- ngx.exit(500)
ngx.say(cjson.encode(result))
ngx.flush()
end
嗨,大家好,请教一个问题。
写了如上的一段测试代码,使用posix的api,fork了一个子进程,在子进程当中sleep 5秒。
结果,使用客户端请求该段代码的时候,发现ngx.say 无法同步输出结果,然后结束请求,必须等到子进程运行结束之后,整个请求才能断开,请教一下,是什么问题?
多谢了!