本文介绍了我怎样才能prevent僵尸子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个使用叉()产卵处理客户端连接的服务器。服务器并不需要知道发生了什么分叉过程 - 他们对自己的工作,他们正在做的时候,他们应该不是死成为僵尸。什么是实现这个简单的方法?

I am writing a server that uses fork() to spawn handlers for client connections. The server does not need to know about what happens to the forked processes – they work on their own, and when they're done, they should just die instead of becoming zombies. What is an easy way to accomplish this?

推荐答案

有几种方法,但使用与 SA_NOCLDWAIT 在父进程可能是一个最简单的:

There are several ways, but using sigaction with SA_NOCLDWAIT in the parent process is probably the easiest one:

struct sigaction sigchld_action = {
  .sa_handler = SIG_DFL,
  .sa_flags = SA_NOCLDWAIT
};
sigaction(SIGCHLD, &sigchld_action, NULL);

这篇关于我怎样才能prevent僵尸子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-25 18:54