Middle+
What is a zombie process?
sobes.tech AI
Answer from AI
A zombie process is a process in the operating system that has finished execution, but its parent process has not yet called the wait() system call to retrieve its exit status. As a result, the process remains in the process table as a "zombie" and occupies a slot, even though it is no longer running.
In Go, as in other languages, if you launch external processes using os/exec and do not call Wait(), the child processes can become zombies.
Example:
cmd := exec.Command("sleep", "1")
err := cmd.Start()
if err != nil {
log.Fatal(err)
}
// If you do not call cmd.Wait(), the process may remain a zombie
// cmd.Wait() // must be called to avoid zombies
To prevent zombie processes, always call Wait() after Start() for child processes.