A server application forks multiple worker processes to handle tasks concurrently. However, the system administrator notices an increasing number of <defunct> processes over time. What modification to the application's code is the standard method to ensure these defunct entries are cleaned up without restarting the server or halting its concurrent operation?
Invoke the wait() system call in the parent process immediately after each fork() call.
Add a signal handler for SIGCHLD that calls waitpid() to reap the terminated child processes.
Send the SIGKILL signal to the process IDs (PIDs) of the defunct processes to force their removal.
Schedule a periodic restart of the service to clear the accumulated defunct entries from the process table.
Defunct entries are zombie processes whose exit statuses have not been collected by their parent. The standard solution is to install a signal handler for the SIGCHLD signal. This signal is sent to the parent process whenever a child process terminates. The handler can then call the wait() or waitpid() system call to reap the child, which removes its entry from the process table. Restarting the service is a temporary fix, as it causes the init process to adopt and reap the zombies, but it doesn't solve the underlying issue. Sending SIGKILL is ineffective because a zombie process is already dead. Invoking wait() immediately after each fork() would serialize the process, defeating the purpose of forking concurrent workers.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is a zombie process in Linux?
Open an interactive chat with Bash
How does the `SIGCHLD` signal help manage child processes?
Open an interactive chat with Bash
What is the difference between `wait()` and `waitpid()`?