当我生成进程时出现僵尸进程
我有一段代码,我在其中生成子进程以使其更加高效。然而,他们似乎创建了各种僵尸进程,这些进程会阻塞套接字并导致站点瘫痪。
spawn(:method => :thread) do
if @login_user.suggested_group_info.new_record?
xxx
end
end
1)为什么会创建僵尸进程? 2)我怎样才能编写代码,确保在进程变成僵尸之前将其杀死?
I have a pieces of code where i spawn off children processes to make it more efficient. However, they appear to create all sorts of zombie processes which block sockets and bring down the site.
spawn(:method => :thread) do
if @login_user.suggested_group_info.new_record?
xxx
end
end
1) Why is this creating zombie processes?
2) How could i write the code such that i make sure i kill the process before it becomes a zombie?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须保存生成的进程的 PID,并在其终止后对其执行 waitpid(2) 系统调用。 (我不知道 Ruby 是如何做到这一点的。)
You have to save the PID of the spawned process and execute the waitpid(2) system call upon it after it dies. (I don't know how Ruby does this.)
您还可以捕获子进程关闭,这将清理僵尸进程
You can also trap for the child shutdown which will clean up the zombie process