Question

I have a program wherein i use fork. In the child process, i just login to a remote server and executes a command. In the parent process, i wait for the child to finish its task. If it doesnot finish it in a predetermined amount of time, i kill the child process using kill(child_pid, SIGTERM). But i have noticed that this leaves behind zombie process like

93113 s000  Z+ 0:00.00 (ssh)

and as the timeouts increase, the zombie process also increase and ultimately the ssh cannot be used anymore.

how can i kill the child process without creating zombies that haunt me??

Was it helpful?

Solution

Even if you kill the child, you still need to wait for it.

OTHER TIPS

You must listen for SIGCHLD in the parent process and get the exit code of the child using wait() et al.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top