How can I prevent zombie child processes?
问题 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? 回答1: 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